home *** CD-ROM | disk | FTP | other *** search
/ Mastering MFC Development / MMD.ISO / labs / c13 / lab01 / ex01 / modayrx.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-20  |  2.4 KB  |  108 lines

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