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.

153 lines
3.7 KiB

  1. // Dglogs.cpp : Implementation of DLL Exports.
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f Dglogsps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include <initguid.h>
  8. #include "Dglogs.h"
  9. #include "Dglogs_i.c"
  10. #include "DglogsCom.h"
  11. #include "Diagnostics.h"
  12. #include "dgnet.h"
  13. extern GUID CLSID_Dgnet;
  14. CComModule _Module;
  15. // COM Map takes care of registering the dgnet.dll
  16. // the CDglogsCom and CGotNet are regestered
  17. //
  18. BEGIN_OBJECT_MAP(ObjectMap)
  19. OBJECT_ENTRY(CLSID_DglogsCom, CDglogsCom)
  20. OBJECT_ENTRY(CLSID_Dgnet, CGotNet)
  21. END_OBJECT_MAP()
  22. // Global variables
  23. //
  24. HMODULE g_hModule;
  25. // Netsh functions
  26. //
  27. STDAPI RegisterhNetshHelper();
  28. STDAPI UnRegisterNetShHelper();
  29. /////////////////////////////////////////////////////////////////////////////
  30. // DLL Entry Point
  31. extern "C"
  32. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  33. {
  34. if (dwReason == DLL_PROCESS_ATTACH)
  35. {
  36. _Module.Init(ObjectMap, hInstance, &LIBID_DGLOGSLib);
  37. DisableThreadLibraryCalls(hInstance);
  38. g_hModule = (HMODULE) hInstance;
  39. }
  40. else if (dwReason == DLL_PROCESS_DETACH)
  41. _Module.Term();
  42. return TRUE; // ok
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // Used to determine whether the DLL can be unloaded by OLE
  46. STDAPI DllCanUnloadNow(void)
  47. {
  48. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  49. }
  50. /////////////////////////////////////////////////////////////////////////////
  51. // Returns a class factory to create an object of the requested type
  52. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  53. {
  54. return _Module.GetClassObject(rclsid, riid, ppv);
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. // DllRegisterServer - Adds entries to the system registry
  58. STDAPI DllRegisterServer(void)
  59. {
  60. // Register with Netsh
  61. RegisterhNetshHelper();
  62. // registers object, typelib and all interfaces in typelib
  63. return _Module.RegisterServer(TRUE);
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // DllUnregisterServer - Removes entries from the system registry
  67. STDAPI DllUnregisterServer(void)
  68. {
  69. // Unregister from netsh
  70. UnRegisterNetShHelper();
  71. return _Module.UnregisterServer(TRUE);
  72. }
  73. STDAPI RegisterhNetshHelper()
  74. {
  75. HKEY hNetSh;
  76. long lRet = NOERROR;
  77. WCHAR szwModule[MAX_PATH];
  78. HRESULT hr;
  79. // Open the netsh registry entry
  80. //
  81. lRet = RegOpenKey(HKEY_LOCAL_MACHINE,
  82. L"SOFTWARE\\Microsoft\\NetSh",
  83. &hNetSh);
  84. if( ERROR_SUCCESS == lRet )
  85. {
  86. // Get the dll filename
  87. //
  88. if( GetModuleFileName( (HMODULE)g_hModule, szwModule, MAX_PATH ) )
  89. {
  90. // Add dglogs under netsh
  91. //
  92. lRet = RegSetValueEx(hNetSh,
  93. L"dglogs",
  94. 0,
  95. REG_SZ,
  96. (CONST BYTE *)szwModule,
  97. (lstrlen(szwModule)+1) * sizeof(WCHAR) );
  98. }
  99. // Close the regsitry key
  100. //
  101. RegCloseKey(hNetSh);
  102. }
  103. return lRet == ERROR_SUCCESS ? NOERROR:ERROR;
  104. }
  105. STDAPI UnRegisterNetShHelper()
  106. {
  107. HKEY hNetSh;
  108. long lRet = NOERROR;
  109. // Open the netsh registry entry
  110. //
  111. lRet = RegOpenKey(HKEY_LOCAL_MACHINE,
  112. L"SOFTWARE\\Microsoft\\NetSh",
  113. &hNetSh);
  114. if( ERROR_SUCCESS == lRet )
  115. {
  116. // Delete our entry
  117. //
  118. RegDeleteValue(hNetSh,L"dglogs");
  119. RegCloseKey(hNetSh);
  120. }
  121. return lRet;
  122. }