summaryrefslogtreecommitdiff
path: root/Checklist/Checklist.cpp
blob: c824e68f88891735d7853db27a49ce9e0b9d1586 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Checklist.cpp : Implementation of WinMain


// Note: Proxy/Stub Information
//      To build a separate proxy/stub DLL, 
//      run nmake -f Checklistps.mk in the project directory.

#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "Checklist.h"

#include "Checklist_i.c"
#include "../common/Interfaces.cpp"

/*#include <path.h>
#include <appmisc.h>
#include <mystring.h>*/

CChecklistApp _Module;

/*
BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()
*/

// const DWORD dwPause = 1000; // time to wait for threads to finish up

LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
{
    while (p1 != NULL && *p1 != NULL)
    {
        LPCTSTR p = p2;
        while (p != NULL && *p != NULL)
        {
            if (*p1 == *p)
                return CharNext(p1);
            p = CharNext(p);
        }
        p1 = CharNext(p1);
    }
    return NULL;
}

/////////////////////////////////////////////////////////////////////////////
//
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance, 
    HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int /*nShowCmd*/)
{
    lpCmdLine = GetCommandLine(); //this line necessary for _ATL_MIN_CRT

#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
    HRESULT hRes = CoInitializeEx(NULL, COINIT_MULTITHREADED);
#else
    HRESULT hRes = CoInitialize(NULL);
#endif

    _ASSERTE(SUCCEEDED(hRes));
    _Module.Init(NULL/*ObjectMap*/, hInstance, &LIBID_CHECKLISTLib);
//    _Module.dwThreadID = GetCurrentThreadId();
    TCHAR szTokens[] = _T("-/");

    int nRet = 0;
    BOOL bRun = TRUE;
    LPCTSTR lpszToken = FindOneOf(lpCmdLine, szTokens);
    while (lpszToken != NULL)
    {
        if (lstrcmpi(lpszToken, _T("UnregServer"))==0)
        {
//            _Module.UpdateRegistryFromResource(IDR_Checklist, FALSE);
//            nRet = _Module.UnregisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        if (lstrcmpi(lpszToken, _T("RegServer"))==0)
        {
			_Module.RegisterDlls();

//            _Module.UpdateRegistryFromResource(IDR_Checklist, TRUE);
//            nRet = _Module.RegisterServer(TRUE);
            bRun = FALSE;
            break;
        }
        lpszToken = FindOneOf(lpszToken, szTokens);
    }

    if (bRun)
    {
//        _Module.StartMonitor();
#if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED)
//        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
//            REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED);
        _ASSERTE(SUCCEEDED(hRes));
//        hRes = CoResumeClassObjects();
#else
//        hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, 
//            REGCLS_MULTIPLEUSE);
#endif
//        _ASSERTE(SUCCEEDED(hRes));

		if(_Module.InitInstance())
		{

			MSG msg;
			while (GetMessage(&msg, 0, 0, 0))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

//			_Module.RevokeClassObjects();
//			Sleep(dwPause); //wait for any threads to finish
		}

		_Module.ExitInstance();
    }

    _Module.Term();
    CoUninitialize();
    return nRet;
}