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.

222 lines
5.7 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. // tscc.cpp : Implementation of DLL Exports.
  3. // Note: Proxy/Stub Information
  4. // To build a separate proxy/stub DLL,
  5. // run nmake -f tsccps.mk in the project directory.
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "initguid.h"
  9. #include "tscc.h"
  10. #include "tswiz_i.c"
  11. #include "tscc_i.c"
  12. #include "srvsetex_i.c"
  13. #include "Compdata.h"
  14. LONG RecursiveDeleteKey( HKEY hKeyParent , LPTSTR lpszKeyChild );
  15. extern const GUID GUID_ResultNode = { 0xfe8e7e84 , 0x6f63 , 0x11d2 , { 0x98, 0xa9 , 0x0 , 0x0a0 , 0xc9 , 0x25 , 0xf9 , 0x17 } };
  16. TCHAR tchSnapKey[] = TEXT( "Software\\Microsoft\\MMC\\Snapins\\" );
  17. TCHAR tchNameString[] = TEXT( "NameString" );
  18. TCHAR tchNameStringIndirect[] = TEXT( "NameStringIndirect" );
  19. TCHAR tchAbout[] = TEXT( "About" );
  20. TCHAR tchNodeType[] = TEXT( "NodeTypes" );
  21. TCHAR tchStandAlone[] = TEXT( "StandAlone" );
  22. CComModule _Module;
  23. BEGIN_OBJECT_MAP(ObjectMap)
  24. OBJECT_ENTRY(CLSID_Compdata, CCompdata)
  25. END_OBJECT_MAP()
  26. /////////////////////////////////////////////////////////////////////////////
  27. // DLL Entry Point
  28. extern "C"
  29. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  30. {
  31. if (dwReason == DLL_PROCESS_ATTACH)
  32. {
  33. _Module.Init(ObjectMap, hInstance);
  34. DisableThreadLibraryCalls(hInstance);
  35. }
  36. else if (dwReason == DLL_PROCESS_DETACH)
  37. _Module.Term();
  38. return TRUE; // ok
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Used to determine whether the DLL can be unloaded by OLE
  42. STDAPI DllCanUnloadNow(void)
  43. {
  44. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. // Returns a class factory to create an object of the requested type
  48. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  49. {
  50. return _Module.GetClassObject(rclsid, riid, ppv);
  51. }
  52. /////////////////////////////////////////////////////////////////////////////
  53. // DllRegisterServer - Adds entries to the system registry
  54. STDAPI DllRegisterServer(void)
  55. {
  56. HKEY hKeyRoot , hKey;
  57. TCHAR tchGUID[ 40 ];
  58. TCHAR tchKey[ MAX_PATH ];//TEXT( "Software\\Microsoft\\MMC\\Snapins\\" );
  59. lstrcpy( tchKey , tchSnapKey );
  60. StringFromGUID2( CLSID_Compdata , tchGUID , SIZE_OF_BUFFER( tchGUID ) );
  61. lstrcat( tchKey , tchGUID );
  62. if( RegCreateKey( HKEY_LOCAL_MACHINE , tchKey , &hKeyRoot ) != ERROR_SUCCESS )
  63. {
  64. return GetLastError( );
  65. }
  66. TCHAR tchBuf[ MAX_PATH ];
  67. TCHAR tchSysDllPathName[ MAX_PATH + 1];
  68. DWORD dwLen;
  69. dwLen = GetModuleFileName( _Module.GetResourceInstance( ) , tchSysDllPathName , MAX_PATH );
  70. // Null terminate the end of string, prefast is complaining about it BUG: 617151
  71. // GetModuleFileName returns the length of the string, if it fails it returns 0
  72. tchSysDllPathName[dwLen] = L'\0';
  73. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_NAMESTRING , tchBuf , SIZE_OF_BUFFER( tchBuf ) ) );
  74. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchNameString , NULL , REG_SZ , ( PBYTE )&tchBuf[ 0 ] , SIZE_OF_BUFFER( tchBuf ) ) );
  75. wsprintf( tchBuf , L"@%s,-%d", tchSysDllPathName , IDS_NAMESTRING );
  76. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchNameStringIndirect , NULL , REG_SZ , ( PBYTE )&tchBuf[ 0 ] , SIZE_OF_BUFFER( tchBuf ) ) );
  77. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchAbout , NULL , REG_SZ , ( PBYTE )&tchGUID[ 0 ] , sizeof( tchGUID ) ) );
  78. lstrcpy( tchKey , tchStandAlone );
  79. RegCreateKey( hKeyRoot , tchKey , &hKey );
  80. RegCloseKey( hKey );
  81. lstrcpy( tchKey , tchNodeType );
  82. RegCreateKey( hKeyRoot , tchKey , &hKey );
  83. TCHAR szGUID[ 40 ];
  84. HKEY hDummy;
  85. StringFromGUID2( GUID_ResultNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  86. RegCreateKey( hKey , szGUID , &hDummy );
  87. RegCloseKey( hDummy );
  88. RegCloseKey( hKey );
  89. RegCloseKey( hKeyRoot );
  90. return _Module.RegisterServer(TRUE);
  91. }
  92. /////////////////////////////////////////////////////////////////////////////
  93. // DllUnregisterServer - Removes entries from the system registry
  94. STDAPI DllUnregisterServer(void)
  95. {
  96. HKEY hKey;
  97. TCHAR tchGUID[ 40 ];
  98. TCHAR tchKey[ MAX_PATH ];
  99. lstrcpy( tchKey , tchSnapKey );
  100. if( RegOpenKey( HKEY_LOCAL_MACHINE , tchKey , &hKey ) != ERROR_SUCCESS )
  101. {
  102. return GetLastError( ) ;
  103. }
  104. StringFromGUID2( CLSID_Compdata , tchGUID , SIZE_OF_BUFFER( tchGUID ) );
  105. RecursiveDeleteKey( hKey , tchGUID );
  106. RegCloseKey( hKey );
  107. _Module.UnregisterServer();
  108. return S_OK;
  109. }
  110. //---------------------------------------------------------------------------
  111. // Delete a key and all of its descendents.
  112. //---------------------------------------------------------------------------
  113. LONG RecursiveDeleteKey( HKEY hKeyParent , LPTSTR lpszKeyChild )
  114. {
  115. // Open the child.
  116. HKEY hKeyChild;
  117. LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild , 0 , KEY_ALL_ACCESS, &hKeyChild);
  118. if (lRes != ERROR_SUCCESS)
  119. {
  120. return lRes;
  121. }
  122. // Enumerate all of the decendents of this child.
  123. FILETIME time;
  124. TCHAR szBuffer[256];
  125. DWORD dwSize = SIZE_OF_BUFFER( szBuffer );
  126. while( RegEnumKeyEx( hKeyChild , 0 , szBuffer , &dwSize , NULL , NULL , NULL , &time ) == S_OK )
  127. {
  128. // Delete the decendents of this child.
  129. lRes = RecursiveDeleteKey(hKeyChild, szBuffer);
  130. if (lRes != ERROR_SUCCESS)
  131. {
  132. RegCloseKey(hKeyChild);
  133. return lRes;
  134. }
  135. dwSize = SIZE_OF_BUFFER( szBuffer );
  136. }
  137. // Close the child.
  138. RegCloseKey( hKeyChild );
  139. // Delete this child.
  140. return RegDeleteKey( hKeyParent , lpszKeyChild );
  141. }