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.

115 lines
2.7 KiB

  1. // CfgMnt.cpp : Implementation of WinMain
  2. // Note: Proxy/Stub Information
  3. // To build a separate proxy/stub DLL,
  4. // run nmake -f CfgMntps.mk in the project directory.
  5. #include "stdafx.h"
  6. #include "resource.h"
  7. #include "initguid.h"
  8. #include "CfgMnt.h"
  9. #include "CfgMnt_i.c"
  10. #include "CfgMntAdmin.h"
  11. #include "CfgMntVersions.h"
  12. #include "CfgMntModule.h"
  13. LONG CExeModule::Unlock()
  14. {
  15. LONG l = CComModule::Unlock();
  16. if (l == 0)
  17. {
  18. #if _WIN32_WINNT >= 0x0400
  19. if (CoSuspendClassObjects() == S_OK)
  20. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  21. #else
  22. PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  23. #endif
  24. }
  25. return l;
  26. }
  27. CExeModule _Module;
  28. BEGIN_OBJECT_MAP(ObjectMap)
  29. OBJECT_ENTRY(CLSID_CfgMntVersions, CCfgMntVersions)
  30. OBJECT_ENTRY(CLSID_CfgMntAdmin, CCfgMntAdmin)
  31. END_OBJECT_MAP()
  32. LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
  33. {
  34. while (*p1 != NULL)
  35. {
  36. LPCTSTR p = p2;
  37. while (*p != NULL)
  38. {
  39. if (*p1 == *p++)
  40. return p1+1;
  41. }
  42. p1++;
  43. }
  44. return NULL;
  45. }
  46. /////////////////////////////////////////////////////////////////////////////
  47. //
  48. extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
  49. HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
  50. {
  51. lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
  52. // HRESULT hRes = CoInitialize(NULL);
  53. // If you are running on NT 4.0 or higher you can use the following call
  54. // instead to make the EXE free threaded.
  55. // This means that calls come in on a random RPC thread
  56. HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  57. _ASSERTE(SUCCEEDED(hRes));
  58. _Module.Init(ObjectMap, hInstance);
  59. _Module.dwThreadID = GetCurrentThreadId();
  60. TCHAR szTokens[] = _T("-/");
  61. int nRet = 0;
  62. BOOL bRun = TRUE;
  63. LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  64. while (lpszToken != NULL)
  65. {
  66. if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
  67. {
  68. _Module.UpdateRegistryFromResource(IDR_CfgMnt, FALSE);
  69. nRet = _Module.UnregisterServer();
  70. bRun = FALSE;
  71. break;
  72. }
  73. if (lstrcmpi(lpszToken, _T("RegServer"))==0)
  74. {
  75. _Module.UpdateRegistryFromResource(IDR_CfgMnt, TRUE);
  76. nRet = _Module.RegisterServer(TRUE);
  77. bRun = FALSE;
  78. break;
  79. }
  80. lpszToken = FindOneOf(lpszToken, szTokens);
  81. }
  82. if (bRun)
  83. {
  84. hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
  85. REGCLS_MULTIPLEUSE);
  86. _ASSERTE(SUCCEEDED(hRes));
  87. ////////////////////////////////////////////////////////////
  88. CCfgMntModule CfgMntModule;
  89. ////////////////////////////////////////////////////////////
  90. MSG msg;
  91. while (GetMessage(&msg, 0, 0, 0))
  92. DispatchMessage(&msg);
  93. _Module.RevokeClassObjects();
  94. }
  95. _Module.Term();
  96. CoUninitialize();
  97. return nRet;
  98. }