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.

190 lines
5.0 KiB

  1. //***************************************************************************
  2. //
  3. // MAINDLL.CPP
  4. //
  5. // Module: WMI Instance provider code for boot parameters
  6. //
  7. // Purpose: Contains DLL entry points. Also has code that controls
  8. // when the DLL can be unloaded by tracking the number of
  9. // objects and locks as well as routines that support
  10. // self registration.
  11. //
  12. // Copyright (c) 1997-1999 Microsoft Corporation
  13. //
  14. //***************************************************************************
  15. #include <initguid.h>
  16. #include <objbase.h>
  17. #include "bootini.h"
  18. HMODULE ghModule;
  19. // TODO, GuidGen should be used to generate a unique number for any
  20. // providers that are going to be used for anything more extensive
  21. // than just testing.
  22. DEFINE_GUID(CLSID_instprovider,0x22cb8761, 0x914a, 0x11cf, 0xb7, 0x5, 0x0, 0xaa, 0x0, 0x62, 0xcb, 0xb8);
  23. // {22CB8761-914A-11cf-B705-00AA0062CBB8}
  24. //Count number of objects and number of locks.
  25. long g_cObj=0;
  26. long g_cLock=0;
  27. //***************************************************************************
  28. //
  29. // LibMain32
  30. //
  31. // Purpose: Entry point for DLL.
  32. //
  33. // Return: TRUE if OK.
  34. //
  35. //***************************************************************************
  36. BOOL WINAPI LibMain32(HINSTANCE hInstance, ULONG ulReason
  37. , LPVOID pvReserved)
  38. {
  39. if (DLL_PROCESS_ATTACH==ulReason)
  40. ghModule = hInstance;
  41. return TRUE;
  42. }
  43. //***************************************************************************
  44. //
  45. // DllGetClassObject
  46. //
  47. // Purpose: Called by Ole when some client wants a class factory. Return
  48. // one only if it is the sort of class this DLL supports.
  49. //
  50. //***************************************************************************
  51. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, PPVOID ppv)
  52. {
  53. HRESULT hr;
  54. CBootProvFactory *pObj;
  55. if (CLSID_instprovider!=rclsid)
  56. return E_FAIL;
  57. pObj=new CBootProvFactory();
  58. if (NULL==pObj)
  59. return E_OUTOFMEMORY;
  60. hr=pObj->QueryInterface(riid, ppv);
  61. if (FAILED(hr))
  62. delete pObj;
  63. return hr;
  64. }
  65. //***************************************************************************
  66. //
  67. // DllCanUnloadNow
  68. //
  69. // Purpose: Called periodically by Ole in order to determine if the
  70. // DLL can be freed.
  71. //
  72. // Return: S_OK if there are no objects in use and the class factory
  73. // isn't locked.
  74. //
  75. //***************************************************************************
  76. STDAPI DllCanUnloadNow(void)
  77. {
  78. SCODE sc;
  79. //It is OK to unload if there are no objects or locks on the
  80. // class factory.
  81. sc=(0L==g_cObj && 0L==g_cLock) ? S_OK : S_FALSE;
  82. return sc;
  83. }
  84. //***************************************************************************
  85. //
  86. // DllRegisterServer
  87. //
  88. // Purpose: Called during setup or by regsvr32.
  89. //
  90. // Return: NOERROR if registration successful, error otherwise.
  91. //***************************************************************************
  92. STDAPI DllRegisterServer(void)
  93. {
  94. char szID[128];
  95. WCHAR wcID[128];
  96. char szCLSID[128];
  97. char szModule[MAX_PATH];
  98. char * pName = "WMI Boot Instance Provider";
  99. char * pModel = "Both";
  100. HKEY hKey1, hKey2;
  101. // Create the path.
  102. StringFromGUID2(CLSID_instprovider, wcID, 128);
  103. wcstombs(szID, wcID, 128);
  104. lstrcpy(szCLSID, TEXT("Software\\classes\\CLSID\\"));
  105. lstrcat(szCLSID, szID);
  106. // Create entries under CLSID
  107. RegCreateKey(HKEY_LOCAL_MACHINE, szCLSID, &hKey1);
  108. RegSetValueEx(hKey1, NULL, 0, REG_SZ, (BYTE *)pName, lstrlen(pName)+1);
  109. RegCreateKey(hKey1,"InprocServer32",&hKey2);
  110. GetModuleFileName(ghModule, szModule, MAX_PATH);
  111. RegSetValueEx(hKey2, NULL, 0, REG_SZ, (BYTE *)szModule,
  112. lstrlen(szModule)+1);
  113. RegSetValueEx(hKey2, "ThreadingModel", 0, REG_SZ,
  114. (BYTE *)pModel, lstrlen(pModel)+1);
  115. RegCloseKey(hKey1);
  116. RegCloseKey(hKey2);
  117. return NOERROR;
  118. }
  119. //***************************************************************************
  120. //
  121. // DllUnregisterServer
  122. //
  123. // Purpose: Called when it is time to remove the registry entries.
  124. //
  125. // Return: NOERROR if registration successful, error otherwise.
  126. //***************************************************************************
  127. STDAPI DllUnregisterServer(void)
  128. {
  129. char szID[128];
  130. WCHAR wcID[128];
  131. char szCLSID[128];
  132. HKEY hKey;
  133. // Create the path using the CLSID
  134. StringFromGUID2(CLSID_instprovider, wcID, 128);
  135. wcstombs(szID, wcID, 128);
  136. lstrcpy(szCLSID, TEXT("Software\\classes\\CLSID\\"));
  137. lstrcat(szCLSID, szID);
  138. // First delete the InProcServer subkey.
  139. DWORD dwRet = RegOpenKey(HKEY_LOCAL_MACHINE, szCLSID, &hKey);
  140. if(dwRet == NO_ERROR)
  141. {
  142. RegDeleteKey(hKey, "InProcServer32");
  143. RegCloseKey(hKey);
  144. }
  145. dwRet = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\classes\\CLSID", &hKey);
  146. if(dwRet == NO_ERROR)
  147. {
  148. RegDeleteKey(hKey,szID);
  149. RegCloseKey(hKey);
  150. }
  151. return NOERROR;
  152. }