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.

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