Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.4 KiB

  1. // WhqlProv.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f WhqlProps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include <initguid.h>
  8. #include "WhqlProv.h"
  9. #include "WhqlProv_i.c"
  10. #include "WhqlObj.h"
  11. CComModule _Module;
  12. BEGIN_OBJECT_MAP(ObjectMap)
  13. OBJECT_ENTRY(CLSID_WhqlObj, CWhqlObj)
  14. END_OBJECT_MAP()
  15. class CWhqlProApp : public CWinApp
  16. {
  17. public:
  18. // Overrides
  19. // ClassWizard generated virtual function overrides
  20. //{{AFX_VIRTUAL(CWhqlProApp)
  21. public:
  22. virtual BOOL InitInstance();
  23. virtual int ExitInstance();
  24. //}}AFX_VIRTUAL
  25. //{{AFX_MSG(CWhqlProApp)
  26. // NOTE - the ClassWizard will add and remove member functions here.
  27. // DO NOT EDIT what you see in these blocks of generated code !
  28. //}}AFX_MSG
  29. DECLARE_MESSAGE_MAP()
  30. };
  31. BEGIN_MESSAGE_MAP(CWhqlProApp, CWinApp)
  32. //{{AFX_MSG_MAP(CWhqlProApp)
  33. // NOTE - the ClassWizard will add and remove mapping macros here.
  34. // DO NOT EDIT what you see in these blocks of generated code!
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. CWhqlProApp theApp;
  38. BOOL CWhqlProApp::InitInstance()
  39. {
  40. _Module.Init(ObjectMap, m_hInstance, &LIBID_WHQLPROLib);
  41. return CWinApp::InitInstance();
  42. }
  43. int CWhqlProApp::ExitInstance()
  44. {
  45. _Module.Term();
  46. return CWinApp::ExitInstance();
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Used to determine whether the DLL can be unloaded by OLE
  50. STDAPI DllCanUnloadNow(void)
  51. {
  52. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  53. return (AfxDllCanUnloadNow()==S_OK && _Module.GetLockCount()==0) ? S_OK : S_FALSE;
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // Returns a class factory to create an object of the requested type
  57. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  58. {
  59. return _Module.GetClassObject(rclsid, riid, ppv);
  60. }
  61. /////////////////////////////////////////////////////////////////////////////
  62. // DllRegisterServer - Adds entries to the system registry
  63. STDAPI DllRegisterServer(void)
  64. {
  65. // registers object, typelib and all interfaces in typelib
  66. HRESULT hr = _Module.RegisterServer(TRUE);
  67. if( FAILED(hr) )
  68. return hr;
  69. //Compile the MOF File.
  70. IMofCompiler* pMofComp = NULL;
  71. hr = CoCreateInstance(CLSID_MofCompiler , NULL , CLSCTX_ALL , IID_IMofCompiler , (LPVOID*)&pMofComp);
  72. WBEM_COMPILE_STATUS_INFO sMofCompileInfo;
  73. if( SUCCEEDED(hr) )
  74. {
  75. CString sFileName;
  76. TCHAR szFileName[_MAX_PATH+1];
  77. TCHAR szDrive[_MAX_DRIVE];
  78. TCHAR szDir[_MAX_DIR];
  79. ::GetModuleFileName(NULL, szFileName, _MAX_PATH);
  80. _wsplitpath(szFileName, szDrive, szDir, NULL, NULL);
  81. sFileName.Format(TEXT("%s%sWhqlProvider.Mof"), szDrive, szDir);
  82. TRACE(L"Compiling MOF File %s" , sFileName);
  83. hr = pMofComp->CompileFile(
  84. (LPWSTR)LPCTSTR(sFileName),//LPWSTR FileName,
  85. NULL, //LPWSTR ServerAndNamespace,
  86. NULL, //LPWSTR User,
  87. NULL , //LPWSTR Authority,
  88. NULL, //LPWSTR Password,
  89. WBEM_FLAG_CONSOLE_PRINT, //LONG lOptionFlags,
  90. 0, //LONG lClassFlags,
  91. 0, //LONG lInstanceFlags,
  92. &sMofCompileInfo //WBEM_COMPILE_STATUS_INFO* pInfo
  93. );
  94. }
  95. if(pMofComp)
  96. pMofComp->Release();
  97. return hr;
  98. }
  99. /////////////////////////////////////////////////////////////////////////////
  100. // DllUnregisterServer - Removes entries from the system registry
  101. STDAPI DllUnregisterServer(void)
  102. {
  103. return _Module.UnregisterServer(TRUE);
  104. }