source: trunk/Utilities/Miscellaneous/DispEventSample03/DispEventSample03.cpp @ 937

Last change on this file since 937 was 255, checked in by roman, 10 years ago
File size: 2.6 KB
Line 
1// DispEventSample03.cpp : main source file for DispEventSample03.exe
2//
3
4#include "stdafx.h"
5
6#include <atlframe.h>
7#include <atlctrls.h>
8#include <atldlgs.h>
9
10#include "resource.h"
11
12// Note: Proxy/Stub Information
13//              To build a separate proxy/stub DLL,
14//              run nmake -f DispEventSample03ps.mk in the project directory.
15#include "initguid.h"
16#include "DispEventSample03.h"
17#include "DispEventSample03_i.c"
18
19#include "MainDialog.h"
20
21CServerAppModule _Module;
22
23BEGIN_OBJECT_MAP(ObjectMap)
24END_OBJECT_MAP()
25
26int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpstrCmdLine*/, int /*nCmdShow*/)
27{
28        HRESULT hRes = ::CoInitialize(NULL);
29// If you are running on NT 4.0 or higher you can use the following call instead to
30// make the EXE free threaded. This means that calls come in on a random RPC thread.
31//      HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
32        ATLASSERT(SUCCEEDED(hRes));
33
34        // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
35        ::DefWindowProc(NULL, 0, 0, 0L);
36
37        AtlInitCommonControls(ICC_BAR_CLASSES); // add flags to support other controls
38
39        hRes = _Module.Init(ObjectMap, hInstance);
40        ATLASSERT(SUCCEEDED(hRes));
41
42        AtlAxWinInit();
43
44        // Parse command line, register or unregister or run the server
45        int nRet = 0;
46        TCHAR szTokens[] = _T("-/");
47        bool bRun = true;
48        bool bAutomation = false;
49
50        LPCTSTR lpszToken = _Module.FindOneOf(::GetCommandLine(), szTokens);
51        while(lpszToken != NULL)
52        {
53                if(lstrcmpi(lpszToken, _T("UnregServer")) == 0)
54                {
55                        _Module.UpdateRegistryFromResource(IDR_DispEventSample03, FALSE);
56                        nRet = _Module.UnregisterServer(TRUE);
57                        bRun = false;
58                        break;
59                }
60                else if(lstrcmpi(lpszToken, _T("RegServer")) == 0)
61                {
62                        _Module.UpdateRegistryFromResource(IDR_DispEventSample03, TRUE);
63                        nRet = _Module.RegisterServer(TRUE);
64                        bRun = false;
65                        break;
66                }
67                else if((lstrcmpi(lpszToken, _T("Automation")) == 0) ||
68                        (lstrcmpi(lpszToken, _T("Embedding")) == 0))
69                {
70                        bAutomation = true;
71                        break;
72                }
73                lpszToken = _Module.FindOneOf(lpszToken, szTokens);
74        }
75
76        if(bRun)
77        {
78                _Module.StartMonitor();
79                hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
80                ATLASSERT(SUCCEEDED(hRes));
81                hRes = ::CoResumeClassObjects();
82                ATLASSERT(SUCCEEDED(hRes));
83
84                if(bAutomation)
85                {
86                        CMessageLoop theLoop;
87                        nRet = theLoop.Run();
88                }
89                else
90                {
91                        CMainDialog dlgMain;
92                        nRet = dlgMain.DoModal();
93                }
94
95                _Module.RevokeClassObjects();
96                ::Sleep(_Module.m_dwPause);
97        }
98
99        _Module.Term();
100        ::CoUninitialize();
101
102        return nRet;
103}
Note: See TracBrowser for help on using the repository browser.