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.

237 lines
5.8 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 ];
  68. GetModuleFileName( _Module.GetResourceInstance( ) , tchSysDllPathName , sizeof( tchSysDllPathName ) / sizeof( TCHAR ) );
  69. VERIFY_E( 0 , LoadString( _Module.GetResourceInstance( ) , IDS_NAMESTRING , tchBuf , SIZE_OF_BUFFER( tchBuf ) ) );
  70. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchNameString , NULL , REG_SZ , ( PBYTE )&tchBuf[ 0 ] , SIZE_OF_BUFFER( tchBuf ) ) );
  71. wsprintf( tchBuf , L"@%s,-%d", tchSysDllPathName , IDS_NAMESTRING );
  72. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchNameStringIndirect , NULL , REG_SZ , ( PBYTE )&tchBuf[ 0 ] , SIZE_OF_BUFFER( tchBuf ) ) );
  73. VERIFY_S( ERROR_SUCCESS , RegSetValueEx( hKeyRoot , tchAbout , NULL , REG_SZ , ( PBYTE )&tchGUID[ 0 ] , sizeof( tchGUID ) ) );
  74. lstrcpy( tchKey , tchStandAlone );
  75. RegCreateKey( hKeyRoot , tchKey , &hKey );
  76. RegCloseKey( hKey );
  77. lstrcpy( tchKey , tchNodeType );
  78. RegCreateKey( hKeyRoot , tchKey , &hKey );
  79. TCHAR szGUID[ 40 ];
  80. HKEY hDummy;
  81. StringFromGUID2( GUID_ResultNode , szGUID , SIZE_OF_BUFFER( szGUID ) );
  82. RegCreateKey( hKey , szGUID , &hDummy );
  83. RegCloseKey( hDummy );
  84. RegCloseKey( hKey );
  85. RegCloseKey( hKeyRoot );
  86. return _Module.RegisterServer(TRUE);
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. // DllUnregisterServer - Removes entries from the system registry
  90. STDAPI DllUnregisterServer(void)
  91. {
  92. HKEY hKey;
  93. TCHAR tchGUID[ 40 ];
  94. TCHAR tchKey[ MAX_PATH ];
  95. lstrcpy( tchKey , tchSnapKey );
  96. if( RegOpenKey( HKEY_LOCAL_MACHINE , tchKey , &hKey ) != ERROR_SUCCESS )
  97. {
  98. return GetLastError( ) ;
  99. }
  100. StringFromGUID2( CLSID_Compdata , tchGUID , SIZE_OF_BUFFER( tchGUID ) );
  101. RecursiveDeleteKey( hKey , tchGUID );
  102. RegCloseKey( hKey );
  103. _Module.UnregisterServer();
  104. return S_OK;
  105. }
  106. //---------------------------------------------------------------------------
  107. // Delete a key and all of its descendents.
  108. //---------------------------------------------------------------------------
  109. LONG RecursiveDeleteKey( HKEY hKeyParent , LPTSTR lpszKeyChild )
  110. {
  111. // Open the child.
  112. HKEY hKeyChild;
  113. LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild , 0 , KEY_ALL_ACCESS, &hKeyChild);
  114. if (lRes != ERROR_SUCCESS)
  115. {
  116. return lRes;
  117. }
  118. // Enumerate all of the decendents of this child.
  119. FILETIME time;
  120. TCHAR szBuffer[256];
  121. DWORD dwSize = SIZE_OF_BUFFER( szBuffer );
  122. while( RegEnumKeyEx( hKeyChild , 0 , szBuffer , &dwSize , NULL , NULL , NULL , &time ) == S_OK )
  123. {
  124. // Delete the decendents of this child.
  125. lRes = RecursiveDeleteKey(hKeyChild, szBuffer);
  126. if (lRes != ERROR_SUCCESS)
  127. {
  128. RegCloseKey(hKeyChild);
  129. return lRes;
  130. }
  131. dwSize = SIZE_OF_BUFFER( szBuffer );
  132. }
  133. // Close the child.
  134. RegCloseKey( hKeyChild );
  135. // Delete this child.
  136. return RegDeleteKey( hKeyParent , lpszKeyChild );
  137. }
  138. extern "C" BOOL
  139. IsWhistlerAdvanceServer()
  140. {
  141. OSVERSIONINFOEX osVersionInfo;
  142. ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
  143. osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
  144. if (GetVersionEx((LPOSVERSIONINFO )&osVersionInfo))
  145. {
  146. return (osVersionInfo.wSuiteMask & VER_SUITE_ENTERPRISE) ||
  147. (osVersionInfo.wSuiteMask & VER_SUITE_DATACENTER);
  148. }
  149. else
  150. {
  151. return FALSE;
  152. }
  153. }