home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / atlduck / duck / duck.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  3KB  |  122 lines

  1. // duck.cpp : Implementation of WinMain
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12.  
  13. // Note: Proxy/Stub Information
  14. //      To build a separate proxy/stub DLL,
  15. //      run nmake -f duckps.mk in the project directory.
  16.  
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "initguid.h"
  20. #include "duck.h"
  21. #include "mydlg.h"
  22.  
  23. #include "duck_i.c"
  24. #include "duckint.h"
  25.  
  26.  
  27. LONG CExeModule::Unlock()
  28. {
  29.     LONG l = CComModule::Unlock();
  30.     if (l == 0)
  31.     {
  32. #if _WIN32_WINNT >= 0x0400
  33.         if (CoSuspendClassObjects() == S_OK)
  34.             PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  35. #else
  36.         PostThreadMessage(dwThreadID, WM_QUIT, 0, 0);
  37. #endif
  38.     }
  39.     return l;
  40. }
  41.  
  42. CExeModule _Module;
  43.  
  44. BEGIN_OBJECT_MAP(ObjectMap)
  45.     OBJECT_ENTRY(CLSID_DuckInt, CDuckInt)
  46. END_OBJECT_MAP()
  47.  
  48.  
  49. LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
  50. {
  51.     while (*p1 != NULL)
  52.     {
  53.         LPCTSTR p = p2;
  54.         while (*p != NULL)
  55.         {
  56.             if (*p1 == *p++)
  57.                 return p1+1;
  58.         }
  59.         p1++;
  60.     }
  61.     return NULL;
  62. }
  63.  
  64. CMyDlg mydlg;
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
  68.     HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
  69. {
  70.     lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT
  71.     HRESULT hRes = CoInitialize(NULL);
  72. //  If you are running on NT 4.0 or higher you can use the following call
  73. //  instead to make the EXE free threaded.
  74. //  This means that calls come in on a random RPC thread
  75. //  HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  76.     _ASSERTE(SUCCEEDED(hRes));
  77.     _Module.Init(ObjectMap, hInstance);
  78.     _Module.dwThreadID = GetCurrentThreadId();
  79.     TCHAR szTokens[] = _T("-/");
  80.  
  81.     int nRet = 0;
  82.     BOOL bRun = TRUE;
  83.     LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
  84.     while (lpszToken != NULL)
  85.     {
  86.         if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
  87.         {
  88.             _Module.UpdateRegistryFromResource(IDR_Duck, FALSE);
  89.             nRet = _Module.UnregisterServer();
  90.             bRun = FALSE;
  91.             break;
  92.         }
  93.         if (lstrcmpi(lpszToken, _T("RegServer"))==0)
  94.         {
  95.             _Module.UpdateRegistryFromResource(IDR_Duck, TRUE);
  96.             nRet = _Module.RegisterServer(TRUE);
  97.             bRun = FALSE;
  98.             break;
  99.         }
  100.         lpszToken = FindOneOf(lpszToken, szTokens);
  101.     }
  102.  
  103.     if (bRun)
  104.     {
  105.         hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
  106.             REGCLS_MULTIPLEUSE);
  107.         _ASSERTE(SUCCEEDED(hRes));
  108.  
  109.  
  110.         mydlg.DoModal();
  111.  
  112.         _Module.RevokeClassObjects();
  113.     }
  114.  
  115.     CoUninitialize();
  116. #ifdef _ATL_MIN_CRT
  117.     ExitProcess(nRet);
  118. #else
  119.     return nRet;
  120. #endif
  121. }
  122.