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.

214 lines
4.3 KiB

  1. //
  2. // Copyright 1997 - Microsoft
  3. //
  4. //
  5. // DLL.CPP - DLL entry points
  6. //
  7. #include "pch.h"
  8. #include "register.h"
  9. #include "ccomputr.h"
  10. #include "cservice.h"
  11. #include "cgroup.h"
  12. DEFINE_MODULE("IMADMUI")
  13. // DLL Globals
  14. HINSTANCE g_hInstance = NULL;
  15. DWORD g_cObjects = 0;
  16. DWORD g_cLock = 0;
  17. TCHAR g_szDllFilename[ MAX_PATH ] = { 0 };
  18. UINT g_cfDsObjectNames;
  19. UINT g_cfDsDisplaySpecOptions;
  20. UINT g_cfDsPropetyPageInfo;
  21. UINT g_cfMMCGetNodeType;
  22. WCHAR g_cszHelpFile[] = L"rbadmin.hlp";
  23. CRITICAL_SECTION g_InterlockCS;
  24. //
  25. // DLLMain()
  26. //
  27. BOOL WINAPI
  28. DllMain(
  29. HANDLE hInst,
  30. ULONG uReason,
  31. LPVOID lpReserved)
  32. {
  33. if ( uReason == DLL_PROCESS_ATTACH )
  34. {
  35. InitializeCriticalSection( &g_InterlockCS );
  36. }
  37. // keep down the noise
  38. #ifdef DEBUG
  39. if ( g_dwTraceFlags & TF_DLL )
  40. {
  41. TraceFunc( "DllMain() - " );
  42. }
  43. #endif // DEBUG
  44. switch( uReason )
  45. {
  46. case DLL_PROCESS_ATTACH:
  47. TraceMsg( TF_DLL, "DLL_PROCESS_ATTACH - ThreadID = 0x%08x\n", GetCurrentThreadId( ) );
  48. INITIALIZE_TRACE_MEMORY_PROCESS;
  49. g_hInstance = (HINSTANCE) hInst;
  50. TraceAssertIfZero( GetModuleFileName( g_hInstance, g_szDllFilename, ARRAYSIZE( g_szDllFilename ) ) );
  51. break;
  52. case DLL_PROCESS_DETACH:
  53. TraceMsg( TF_DLL, "DLL_PROCESS_DETACH - ThreadID = 0x%08x ", GetCurrentThreadId( ) );
  54. TraceMsg( TF_DLL, "[ g_cLock=%u, g_cObjects=%u ]\n", g_cLock, g_cObjects );
  55. UNINITIALIZE_TRACE_MEMORY;
  56. #ifdef DEBUG
  57. if (g_fDebugInitialized) {
  58. DeleteCriticalSection(&g_DebugCS);
  59. g_fDebugInitialized = FALSE;
  60. }
  61. #endif
  62. DeleteCriticalSection( &g_InterlockCS );
  63. break;
  64. case DLL_THREAD_ATTACH:
  65. TraceMsg( TF_DLL, "DLL_THREAD_ATTACH - ThreadID = 0x%08x ", GetCurrentThreadId( ) );
  66. TraceMsg( TF_DLL, "[ g_cLock=%u, g_cObjects=%u ]\n", g_cLock, g_cObjects );
  67. INITIALIZE_TRACE_MEMORY_THREAD;
  68. break;
  69. case DLL_THREAD_DETACH:
  70. TraceMsg( TF_DLL, "DLL_THREAD_DETACH - ThreadID = 0x%08x ", GetCurrentThreadId( ) );
  71. TraceMsg( TF_DLL, "[ g_cLock=%u, g_cObjects=%u ]\n", g_cLock, g_cObjects );
  72. UNINITIALIZE_TRACE_MEMORY;
  73. break;
  74. }
  75. #ifdef DEBUG
  76. if ( g_dwTraceFlags & TF_DLL )
  77. {
  78. RETURN(TRUE);
  79. }
  80. #endif // DEBUG
  81. return TRUE;
  82. } // DLLMain()
  83. //
  84. // DllGetClassObject()
  85. //
  86. STDAPI
  87. DllGetClassObject(
  88. REFCLSID rclsid,
  89. REFIID riid,
  90. void** ppv )
  91. {
  92. TraceFunc( "DllGetClassObject( ");
  93. if ( !ppv )
  94. {
  95. TraceMsg( TF_FUNC, "ppv == NULL! )\n" );
  96. RRETURN(E_POINTER);
  97. }
  98. LPCFACTORY lpClassFactory;
  99. HRESULT hr = CLASS_E_CLASSNOTAVAILABLE;
  100. int i = 0;
  101. while( g_DllClasses[ i ].rclsid )
  102. {
  103. if ( *g_DllClasses[ i ].rclsid == rclsid )
  104. {
  105. TraceMsg( TF_FUNC, TEXT("rclsid= %s, riid, ppv )\n"), g_DllClasses[ i ].pszName );
  106. hr = S_OK;
  107. break;
  108. }
  109. i++;
  110. }
  111. if ( hr == CLASS_E_CLASSNOTAVAILABLE )
  112. {
  113. TraceMsg( TF_FUNC, "rclsid= " );
  114. TraceMsgGUID( TF_FUNC, rclsid );
  115. TraceMsg( TF_FUNC, ", riid, ppv )\n" );
  116. goto Cleanup;
  117. }
  118. Assert( g_DllClasses[ i ].pfnCreateInstance != NULL );
  119. lpClassFactory =
  120. new CFactory( g_DllClasses[ i ].pfnCreateInstance );
  121. if ( !lpClassFactory )
  122. {
  123. hr = THR(E_OUTOFMEMORY);
  124. goto Cleanup;
  125. }
  126. hr = THR( lpClassFactory->Init( ) );
  127. if ( hr )
  128. {
  129. TraceDo( delete lpClassFactory );
  130. goto Cleanup;
  131. }
  132. hr = lpClassFactory->QueryInterface( riid, ppv );
  133. ((IUnknown *) lpClassFactory )->Release( );
  134. Cleanup:
  135. HRETURN(hr);
  136. }
  137. //
  138. // DllRegisterServer()
  139. //
  140. STDAPI
  141. DllRegisterServer(void)
  142. {
  143. HRESULT hr;
  144. TraceFunc( "DllRegisterServer()\n" );
  145. hr = RegisterDll( TRUE );
  146. HRETURN(hr);
  147. }
  148. //
  149. // DllUnregisterServer()
  150. //
  151. STDAPI
  152. DllUnregisterServer(void)
  153. {
  154. TraceFunc( "DllUnregisterServer()\n" );
  155. HRETURN( RegisterDll( FALSE ) );
  156. }
  157. //
  158. // DllCanUnloadNow()
  159. //
  160. STDAPI
  161. DllCanUnloadNow(void)
  162. {
  163. TraceFunc( "DllCanUnloadNow()\n" );
  164. HRESULT hr = S_OK;
  165. if ( g_cLock || g_cObjects )
  166. {
  167. TraceMsg( TF_DLL, "[ g_cLock=%u, g_cObjects=%u ]\n", g_cLock, g_cObjects );
  168. hr = S_FALSE;
  169. }
  170. HRETURN(hr);
  171. }