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.

89 lines
2.4 KiB

  1. // common tools used by the various logging uis
  2. #include "stdafx.h"
  3. #include "logui.h"
  4. #include "logtools.h"
  5. //---------------------------------------------------------------
  6. // Given the class ID of a server, it goes into the registry and
  7. // sets the Apartment Model flag for that object.
  8. // The strings used here are non-localized. They are also specific
  9. // to this routine.
  10. BOOL FSetObjectApartmentModel( REFCLSID clsid )
  11. {
  12. LPOLESTR pszwSid;
  13. LONG err;
  14. HKEY hKey;
  15. // transform the clsid into a string
  16. StringFromCLSID(
  17. clsid, //CLSID to be converted
  18. &pszwSid //Address of output variable that receives a pointer to the resulting string
  19. );
  20. // put it in a cstring
  21. CString szSid = pszwSid;
  22. // free the ole string
  23. CoTaskMemFree( pszwSid );
  24. // build the registry path
  25. CString szRegPath = _T("CLSID\\");
  26. szRegPath += szSid;
  27. szRegPath += _T("\\InProcServer32");
  28. // prep the apartment name
  29. CString szApartment = _T("Apartment");
  30. // open the registry key
  31. err = RegOpenKey(
  32. HKEY_CLASSES_ROOT, // handle of open key
  33. (LPCTSTR)szRegPath, // address of name of subkey to open
  34. &hKey // address of handle of open key
  35. );
  36. if ( err != ERROR_SUCCESS )
  37. return FALSE;
  38. // set the apartment threading value
  39. err = RegSetValueEx(
  40. hKey, // handle of key to set value for
  41. _T("ThreadingModel"), // address of value to set
  42. 0, // reserved
  43. REG_SZ, // flag for value type
  44. (PBYTE)(LPCTSTR)szApartment, // address of value data
  45. (szApartment.GetLength() + 1) * sizeof(TCHAR) // size of value data
  46. );
  47. if ( err != ERROR_SUCCESS )
  48. return FALSE;
  49. // close the registry key
  50. RegCloseKey( hKey );
  51. return TRUE;
  52. }
  53. //---------------------------------------------------------------
  54. // tests a machine name to see if it is the local machine it is
  55. // talking about
  56. BOOL FIsLocalMachine( LPCTSTR psz )
  57. {
  58. CString szLocal;
  59. DWORD cch = MAX_COMPUTERNAME_LENGTH + 1;
  60. BOOL fAnswer;
  61. // get the actual name of the local machine
  62. fAnswer = GetComputerName(szLocal.GetBuffer(cch), &cch);
  63. szLocal.ReleaseBuffer();
  64. if ( !fAnswer )
  65. return FALSE;
  66. // compare and return
  67. fAnswer = (szLocal.CompareNoCase( psz ) == 0);
  68. return fAnswer;
  69. }