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.

83 lines
2.3 KiB

  1. #include "precomp.h"
  2. #include <commain.h>
  3. #include <clsfac.h>
  4. #include "smtp.h"
  5. #include <TCHAR.h>
  6. #include <strsafe.h>
  7. // {C7A3A54B-0250-11D3-9CD1-00105A1F4801}
  8. const CLSID CLSID_WbemSMTPConsumer =
  9. { 0xc7a3a54b, 0x250, 0x11d3, { 0x9c, 0xd1, 0x0, 0x10, 0x5a, 0x1f, 0x48, 0x1 } };
  10. class CMyServer : public CComServer
  11. {
  12. public:
  13. #ifdef ENABLE_REMOTING
  14. void RegisterMe(CLSID clsID, WCHAR* name)
  15. {
  16. WCHAR wcID[128];
  17. WCHAR szKeyName[128];
  18. HKEY hKey;
  19. // open/create registry entry under CLSID
  20. // not checking returns from string functions - all sizes a known ahead of time
  21. StringFromGUID2(clsID, wcID, 128);
  22. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\CLSID\\"));
  23. StringCchCatW(szKeyName, 128, wcID);
  24. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  25. // set AppID
  26. RegSetValueEx(hKey, L"AppID", 0, REG_SZ, (BYTE*)wcID, 2*(wcslen(wcID) +1));
  27. RegCloseKey(hKey);
  28. // make appID entry w/ DLLSurrogate value
  29. StringCchCopyW(szKeyName, 128, TEXT("SOFTWARE\\Classes\\APPID\\"));
  30. StringCchCatW(szKeyName, 128, wcID);
  31. RegCreateKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  32. RegSetValueEx(hKey, L"DllSurrogate", 0, REG_SZ, (BYTE*)L"\0", 2);
  33. // and a nice name
  34. RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)name, 2*(wcslen(name) +1));
  35. RegCloseKey(hKey);
  36. }
  37. // provider server specific registration
  38. virtual void Register()
  39. {
  40. RegisterMe(CLSID_WbemSMTPConsumer, L"Microsoft WBEM SMTP Event Consumer Provider");
  41. }
  42. void UnregisterMe(CLSID clsID)
  43. {
  44. WCHAR wcID[128];
  45. HKEY hKey;
  46. if (ERROR_SUCCESS == RegOpenKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Classes\\APPID\\"), &hKey))
  47. {
  48. if (0 != StringFromGUID2(clsID, wcID, 128))
  49. {
  50. RegDeleteKey(hKey, wcID);
  51. }
  52. RegCloseKey(hKey);
  53. }
  54. }
  55. virtual void Unregister()
  56. {
  57. UnregisterMe(CLSID_WbemSMTPConsumer);
  58. }
  59. #endif
  60. protected:
  61. HRESULT Initialize()
  62. {
  63. AddClassInfo(CLSID_WbemSMTPConsumer,
  64. new CClassFactory<CSMTPConsumer>(GetLifeControl()),
  65. _T("SMTP Event Consumer Provider"), TRUE);
  66. return S_OK;
  67. }
  68. } g_Server;