Leaked source code of windows server 2003
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.

215 lines
4.2 KiB

  1. #include "common.h"
  2. HINSTANCE g_hGlobalDllInstance = NULL;
  3. PHANDLEMAP g_pGlobalHandleMap = NULL;
  4. LPCWSTR g_wszAdvPackDll = L"advpack.dll";
  5. LPCSTR g_szInstallSection = "install";
  6. LPCSTR g_szUninstallSection = "uninstall";
  7. HRESULT RegisterServer(BOOL fMode);
  8. HRESULT RegisterTypeLibrary(BOOL fMode);
  9. //-----------------------------------------------------------------------------
  10. // DLL Entry Point
  11. //-----------------------------------------------------------------------------
  12. BOOL
  13. WINAPI
  14. DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID pvReserved)
  15. {
  16. BOOL bRet = TRUE;
  17. DEBUG_TRACE(
  18. DLL,
  19. ("dllmain: %s", MapDllReasonToString(dwReason))
  20. );
  21. switch( dwReason )
  22. {
  23. case DLL_PROCESS_ATTACH :
  24. {
  25. DEBUG_INITIALIZE();
  26. g_hGlobalDllInstance = hInstance;
  27. g_pGlobalHandleMap = new HANDLEMAP;
  28. if( g_pGlobalHandleMap )
  29. {
  30. g_pGlobalHandleMap->SetClearFunction(ScriptCallbackKiller);
  31. }
  32. else
  33. {
  34. bRet = FALSE;
  35. }
  36. }
  37. break;
  38. case DLL_PROCESS_DETACH:
  39. {
  40. SAFEDELETE(g_pGlobalHandleMap);
  41. _GetRootKey(FALSE);
  42. DEBUG_TERMINATE();
  43. }
  44. break;
  45. case DLL_THREAD_DETACH:
  46. break;
  47. case DLL_THREAD_ATTACH:
  48. break;
  49. }
  50. return bRet;
  51. }
  52. //-----------------------------------------------------------------------------
  53. // COM Entry Points
  54. //-----------------------------------------------------------------------------
  55. STDAPI
  56. DllRegisterServer(void)
  57. {
  58. return RegisterServer(TRUE);
  59. }
  60. STDAPI
  61. DllUnregisterServer(void)
  62. {
  63. return RegisterServer(FALSE);
  64. }
  65. STDAPI
  66. DllGetClassObject(REFIID clsid, REFIID riid, void** ppv)
  67. {
  68. return CLSFACTORY::Create(clsid, riid, ppv);
  69. }
  70. //-----------------------------------------------------------------------------
  71. // SelfRegistration helper routines
  72. //-----------------------------------------------------------------------------
  73. HRESULT
  74. RegisterServer(BOOL fMode)
  75. {
  76. DEBUG_ENTER((
  77. DBG_DLL,
  78. rt_hresult,
  79. "RegisterServer",
  80. "fMode=%s",
  81. fMode ? g_szInstallSection : g_szUninstallSection
  82. ));
  83. HRESULT hr = S_OK;
  84. HINSTANCE advpack = NULL;
  85. REGINSTALL pfnri = NULL;
  86. advpack = LoadLibrary(g_wszAdvPackDll);
  87. if( !advpack )
  88. {
  89. DEBUG_TRACE(
  90. DLL,
  91. ("couldn't load advpack.dll: %s", MapErrorToString(GetLastError()))
  92. );
  93. hr = E_FAIL;
  94. goto quit;
  95. }
  96. pfnri = (REGINSTALL) GetProcAddress(advpack, achREGINSTALL);
  97. if( !pfnri )
  98. {
  99. DEBUG_TRACE(
  100. DLL,
  101. ("couldn't get RegInstall pointer: %s", MapErrorToString(GetLastError()))
  102. );
  103. hr = E_FAIL;
  104. goto quit;
  105. }
  106. hr = pfnri(
  107. g_hGlobalDllInstance,
  108. fMode ? g_szInstallSection : g_szUninstallSection,
  109. NULL
  110. );
  111. FreeLibrary(advpack);
  112. hr = RegisterTypeLibrary(fMode);
  113. quit:
  114. DEBUG_LEAVE(hr);
  115. return hr;
  116. }
  117. HRESULT
  118. RegisterTypeLibrary(BOOL fMode)
  119. {
  120. DEBUG_ENTER((
  121. DBG_FACTORY,
  122. rt_hresult,
  123. "RegisterTypeLibrary",
  124. "fMode=%s",
  125. fMode ? g_szInstallSection : g_szUninstallSection
  126. ));
  127. ITypeLib* ptl = NULL;
  128. TLIBATTR* pta = NULL;
  129. WCHAR* pbuf = NULL;
  130. HRESULT hr = S_OK;
  131. if( (pbuf = new WCHAR[MAX_PATH]) )
  132. {
  133. GetModuleFileName(g_hGlobalDllInstance, pbuf, MAX_PATH);
  134. }
  135. else
  136. {
  137. hr = E_OUTOFMEMORY;
  138. goto quit;
  139. }
  140. hr = LoadTypeLib(pbuf, &ptl);
  141. if( SUCCEEDED(hr) )
  142. {
  143. if( fMode )
  144. {
  145. hr = RegisterTypeLib(ptl, pbuf, NULL);
  146. }
  147. else
  148. {
  149. hr = ptl->GetLibAttr(&pta);
  150. if( SUCCEEDED(hr) )
  151. {
  152. hr = UnRegisterTypeLib(
  153. pta->guid,
  154. pta->wMajorVerNum,
  155. pta->wMinorVerNum,
  156. pta->lcid,
  157. pta->syskind
  158. );
  159. ptl->ReleaseTLibAttr(pta);
  160. }
  161. else
  162. {
  163. goto quit;
  164. }
  165. }
  166. ptl->Release();
  167. }
  168. quit:
  169. SAFEDELETEBUF(pbuf);
  170. DEBUG_LEAVE(hr);
  171. return hr;
  172. }