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.

163 lines
3.9 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 "dglogsres.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. //#include "Dglogsnetsh.h"
  14. #include <netsh.h>
  15. //#include <netshp.h>
  16. DWORD WINAPI
  17. InitHelperDllEx(
  18. IN DWORD dwNetshVersion,
  19. OUT PVOID pReserved
  20. );
  21. DWORD WINAPI
  22. InitHelperDll(
  23. IN DWORD dwNetshVersion,
  24. OUT PVOID pReserved
  25. )
  26. {
  27. return InitHelperDllEx(dwNetshVersion,pReserved);
  28. }
  29. extern GUID CLSID_Dgnet;
  30. CComModule _Module;
  31. BEGIN_OBJECT_MAP(ObjectMap)
  32. OBJECT_ENTRY(CLSID_DglogsCom, CDglogsCom)
  33. OBJECT_ENTRY(CLSID_Dgnet, CGotNet)
  34. END_OBJECT_MAP()
  35. HMODULE g_hModule;
  36. CDiagnostics g_Diagnostics;
  37. STDAPI RegisterhNetshHelper();
  38. STDAPI UnRegisterNetShHelper();
  39. /////////////////////////////////////////////////////////////////////////////
  40. // DLL Entry Point
  41. extern "C"
  42. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  43. {
  44. if (dwReason == DLL_PROCESS_ATTACH)
  45. {
  46. _Module.Init(ObjectMap, hInstance, &LIBID_DGLOGSLib);
  47. DisableThreadLibraryCalls(hInstance);
  48. g_hModule = (HMODULE) hInstance;
  49. }
  50. else if (dwReason == DLL_PROCESS_DETACH)
  51. _Module.Term();
  52. return TRUE; // ok
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Used to determine whether the DLL can be unloaded by OLE
  56. STDAPI DllCanUnloadNow(void)
  57. {
  58. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  59. }
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Returns a class factory to create an object of the requested type
  62. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  63. {
  64. return _Module.GetClassObject(rclsid, riid, ppv);
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // DllRegisterServer - Adds entries to the system registry
  68. STDAPI DllRegisterServer(void)
  69. {
  70. // Register with Netsh
  71. //RegisterhNetshHelper();
  72. // registers object, typelib and all interfaces in typelib
  73. return _Module.RegisterServer(TRUE);
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // DllUnregisterServer - Removes entries from the system registry
  77. STDAPI DllUnregisterServer(void)
  78. {
  79. // Unregister from netsh
  80. //UnRegisterNetShHelper();
  81. return _Module.UnregisterServer(TRUE);
  82. }
  83. STDAPI RegisterhNetshHelper()
  84. {
  85. HKEY hNetSh;
  86. long lRet = NOERROR;
  87. WCHAR szwModule[MAX_PATH];
  88. HRESULT hr;
  89. // Open the netsh registry entry
  90. //
  91. lRet = RegOpenKey(HKEY_LOCAL_MACHINE,
  92. L"SOFTWARE\\Microsoft\\NetSh",
  93. &hNetSh);
  94. if( ERROR_SUCCESS == lRet )
  95. {
  96. // Get the dll filename
  97. //
  98. if( GetModuleFileName( (HMODULE)g_hModule, szwModule, MAX_PATH ) )
  99. {
  100. // Add dglogs under netsh
  101. //
  102. lRet = RegSetValueEx(hNetSh,
  103. L"dglogs",
  104. 0,
  105. REG_SZ,
  106. (CONST BYTE *)szwModule,
  107. (lstrlen(szwModule)+1) * sizeof(WCHAR) );
  108. }
  109. // Close the regsitry key
  110. //
  111. RegCloseKey(hNetSh);
  112. }
  113. return lRet == ERROR_SUCCESS ? NOERROR:ERROR;
  114. }
  115. STDAPI UnRegisterNetShHelper()
  116. {
  117. HKEY hNetSh;
  118. long lRet = NOERROR;
  119. // Open the netsh registry entry
  120. //
  121. lRet = RegOpenKey(HKEY_LOCAL_MACHINE,
  122. L"SOFTWARE\\Microsoft\\NetSh",
  123. &hNetSh);
  124. if( ERROR_SUCCESS == lRet )
  125. {
  126. // Delete our entry
  127. //
  128. RegDeleteValue(hNetSh,L"dglogs");
  129. RegCloseKey(hNetSh);
  130. }
  131. return lRet;
  132. }