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

  1. // Labrador.cpp : Implementation of EXE registration.
  2. //
  3. // This is a part of the ActiveX Template Library.
  4. // Copyright (C) 1996 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // ActiveX Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // ActiveX Template Library product.
  12.  
  13. #include "prelab.h"
  14. #include "labres.h"
  15. #include "initguid.h"
  16. #include "Labrador.h"
  17. #include "LabObj.h"
  18.  
  19. #define IID_DEFINED
  20. #include "Lab_i.c"
  21.  
  22. CMyModule _Module;
  23.  
  24. BEGIN_OBJECT_MAP(ObjectMap)
  25.     OBJECT_ENTRY(CLSID_Labrador, CLabrador)
  26. END_OBJECT_MAP()
  27.  
  28.  
  29. #ifdef _WINDLL
  30. #error This project does not support DLL, only EXE targets
  31. #endif
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // EXE Entry Point
  35.  
  36. extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
  37.     LPTSTR lpCmdLine, int /*nShowCmd*/)
  38. {
  39.     HRESULT hRes = CoInitialize(NULL);
  40. //  If you are running on NT 4.0 or higher you can use the following call
  41. //  instead to make the EXE free threaded.
  42. //  This means that calls come in on a random RPC thread
  43. //  HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  44.     _ASSERTE(SUCCEEDED(hRes));
  45.     _Module.Init(ObjectMap, hInstance);
  46.  
  47.     // have to remember the hread ID to post a WM_QUIT to it to shut down
  48.     // see the implementation of CMyModule::Unlock() for details
  49.     _Module.dwThreadID = GetCurrentThreadId();
  50.  
  51.     // see if we have to do anything with the registry
  52.     TCHAR szTokens[] = _T("-/");
  53.     LPTSTR lpszToken = _tcstok(lpCmdLine, szTokens);
  54.     while (lpszToken != NULL)
  55.     {
  56.         if (_tcsicmp(lpszToken, _T("UnregServer"))==0)
  57.             return _Module.UnregisterServer();
  58.         else if (_tcsicmp(lpszToken, _T("RegServer"))==0)
  59.         {
  60.             // passing FALSE because we did not link the typelib
  61.             // into the EXE itself
  62.             return _Module.RegisterServer(FALSE);
  63.         }
  64.         lpszToken = _tcstok(NULL, szTokens);
  65.     }
  66.  
  67.     // We are an EXE, just register all the class factories at startup
  68.     hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE);
  69.     _ASSERTE(SUCCEEDED(hRes));
  70.  
  71.     // wait until we get a WM_QUIT
  72.     MSG msg;
  73.     while (GetMessage(&msg, 0, 0, 0))
  74.         DispatchMessage(&msg);
  75.  
  76.     // unregister all the class factories
  77.     _Module.RevokeClassObjects();
  78.  
  79.     CoUninitialize();
  80.     return 0;
  81. }
  82.  
  83.