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

  1. // beeper.cpp : Implementation of CBeeperApp and DLL registration.
  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. #include "prebeep.h"
  14. #include "initguid.h"
  15. #include "beepres.h"
  16. #include "beeper.h"
  17. #include "beepobj.h"
  18.  
  19. #define IID_DEFINED
  20. #include "beeper_i.c"
  21.  
  22. CMyModule _Module;
  23.  
  24. BEGIN_OBJECT_MAP(ObjectMap)
  25.     OBJECT_ENTRY(CLSID_Beeper, CBeeper)
  26. END_OBJECT_MAP()
  27.  
  28. /////////////////////////////////////////////////////////////////////////////
  29. //
  30. #ifndef _WINDLL
  31. extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/,
  32.     LPTSTR lpCmdLine, int /*nShowCmd*/)
  33. {
  34.     HRESULT hRes = CoInitialize(NULL);
  35. //  If you are running on NT 4.0 or higher you can use the following call
  36. //  instead to make the EXE free threaded.
  37. //  This means that calls come in on a random RPC thread
  38. //  HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  39.     ATLASSERT(SUCCEEDED(hRes));
  40.     _Module.Init(ObjectMap, hInstance);
  41.     _Module.dwThreadID = GetCurrentThreadId();
  42.     TCHAR szTokens[] = _T("-/");
  43.  
  44.     LPTSTR lpszToken = _tcstok(lpCmdLine, szTokens);
  45.     while (lpszToken != NULL)
  46.     {
  47.         if (_tcsicmp(lpszToken, _T("UnregServer"))==0)
  48.             return _Module.UnregisterServer();
  49.         else if (_tcsicmp(lpszToken, _T("RegServer"))==0)
  50.             return _Module.RegisterServer(TRUE);
  51.         lpszToken = _tcstok(NULL, szTokens);
  52.     }
  53.  
  54.     hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
  55.         REGCLS_MULTIPLEUSE);
  56.     ATLASSERT(SUCCEEDED(hRes));
  57.  
  58.     MSG msg;
  59.     while (GetMessage(&msg, 0, 0, 0))
  60.         DispatchMessage(&msg);
  61.  
  62.     _Module.RevokeClassObjects();
  63.  
  64.     CoUninitialize();
  65.     return 0;
  66. }
  67. #else
  68. /////////////////////////////////////////////////////////////////////////////
  69. // DLL Entry Point
  70.  
  71. extern "C"
  72. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  73. {
  74.     lpReserved; // to avoid /W4 warning when _MERGE_PROXYSTUB not defined
  75. #ifdef _MERGE_PROXYSTUB
  76.     if (!PrxDllMain(hInstance, dwReason, lpReserved))
  77.         return FALSE;
  78. #endif
  79.     if (dwReason == DLL_PROCESS_ATTACH)
  80.     {
  81.         _Module.Init(ObjectMap, hInstance);
  82.         DisableThreadLibraryCalls(hInstance);
  83.     }
  84.     else if (dwReason == DLL_PROCESS_DETACH)
  85.         _Module.Term();
  86.     return TRUE;    // ok
  87. }
  88. /////////////////////////////////////////////////////////////////////////////
  89. //
  90.  
  91. STDAPI DllCanUnloadNow(void)
  92. {
  93. #ifdef _MERGE_PROXYSTUB
  94.     if (PrxDllCanUnloadNow() != S_OK)
  95.         return S_FALSE;
  96. #endif
  97.     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. //
  102.  
  103. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  104. {
  105. #ifdef _MERGE_PROXYSTUB
  106.     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  107.         return S_OK;
  108. #endif
  109.     return _Module.GetClassObject(rclsid, riid, ppv);
  110. }
  111.  
  112. /////////////////////////////////////////////////////////////////////////////
  113. // DllRegisterServer - Adds entries to the system registry
  114. STDAPI DllRegisterServer(void)
  115. {
  116.     HRESULT hRes = S_OK;
  117. #ifdef _MERGE_PROXYSTUB
  118.     hRes = PrxDllRegisterServer();
  119.     if (FAILED(hRes))
  120.         return hRes;
  121. #endif
  122.     // registers object, typelib and all interfaces in typelib
  123.     hRes = _Module.RegisterServer(TRUE);
  124.     return hRes;
  125. }
  126.  
  127. /////////////////////////////////////////////////////////////////////////////
  128. // DllRegisterServer - Adds entries to the system registry
  129.  
  130. STDAPI DllUnregisterServer(void)
  131. {
  132.     HRESULT hRes = S_OK;
  133.     _Module.UnregisterServer();
  134. #ifdef _MERGE_PROXYSTUB
  135.     hRes = PrxDllUnregisterServer();
  136. #endif
  137.     return hRes;
  138. }
  139.  
  140. #endif //!_WINDLL
  141.