-
Notifications
You must be signed in to change notification settings - Fork 0
/
dllmain.cpp
188 lines (156 loc) · 4.92 KB
/
dllmain.cpp
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//////////////////////////////////////////////////////////////////////////
//
// dllmain.cpp : Implements DLL exports and COM class factory
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// Note: This source file implements the class factory for the DMO,
// plus the following DLL functions:
// - DllMain
// - DllCanUnloadNow
// - DllRegisterServer
// - DllUnregisterServer
// - DllGetClassObject
//
//////////////////////////////////////////////////////////////////////////
/* Modifications made from the sample EVR Presenter are covered under
*
* Copyright (C) 2014 Andrew Van Til
* http://babgvant.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "stdafx.h"
#include "EVRPresenter.h"
#include <initguid.h>
#include "EVRPresenterUuid.h"
HMODULE g_hModule; // DLL module handle
DEFINE_CLASSFACTORY_SERVER_LOCK; // Defines the static member variable for the class factory lock.
// Friendly name for COM registration.
WCHAR* g_sFriendlyName = L"EVR Presenter (babgvant)";
//namespace
//{
//#if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__))
// const std::string path_to_log_file = "./";
//#else
// const std::string path_to_log_file = "/tmp/";
//#endif
//}
// g_ClassFactories: Array of class factory data.
// Defines a look-up table of CLSIDs and corresponding creation functions.
ClassFactoryData g_ClassFactories[] =
{
{ &CLSID_CustomEVRPresenter, EVRCustomPresenter::CreateInstance }
};
const DWORD g_numClassFactories = ARRAY_SIZE(g_ClassFactories);
// DllMain: Entry-point for the DLL.
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
g_hModule = (HMODULE)hModule;
{
HKEY newKey;
WCHAR logPath[_MAX_PATH + 1] = { 0 };
DWORD readType;
DWORD hsize = sizeof(logPath);
DWORD regVal = 0;
bool bGotLogPath = false;
if (RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\babgvant\\EVR Presenter\0",
0, KEY_READ | KEY_QUERY_VALUE, &newKey) == ERROR_SUCCESS)
{
if (RegQueryValueExW(newKey, L"LogFile\0", 0, &readType, (LPBYTE)logPath, &hsize) == ERROR_SUCCESS)
{
bGotLogPath = true;
}
RegCloseKey(newKey);
}
if(bGotLogPath)
TRACE_INIT(logPath);
else
TRACE_INIT(NULL);
}
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
TRACE_CLOSE();
break;
}
return TRUE;
}
STDAPI DllCanUnloadNow()
{
if (!ClassFactory::IsLocked())
{
return S_OK;
}
else
{
return S_FALSE;
}
}
STDAPI DllRegisterServer()
{
HRESULT hr;
// Register the MFT's CLSID as a COM object.
hr = RegisterObject(g_hModule, CLSID_CustomEVRPresenter, g_sFriendlyName, TEXT("Both"));
return hr;
}
STDAPI DllUnregisterServer()
{
// Unregister the CLSID
UnregisterObject(CLSID_CustomEVRPresenter);
return S_OK;
}
STDAPI DllGetClassObject(REFCLSID clsid, REFIID riid, void** ppv)
{
ClassFactory *pFactory = NULL;
HRESULT hr = CLASS_E_CLASSNOTAVAILABLE; // Default to failure
// Find an entry in our look-up table for the specified CLSID.
for (DWORD index = 0; index < g_numClassFactories; index++)
{
if (*g_ClassFactories[index].pclsid == clsid)
{
// Found an entry. Create a new class factory object.
pFactory = new ClassFactory(g_ClassFactories[index].pfnCreate);
if (pFactory)
{
hr = S_OK;
}
else
{
hr = E_OUTOFMEMORY;
}
break;
}
}
if (SUCCEEDED(hr))
{
hr = pFactory->QueryInterface(riid, ppv);
}
SAFE_RELEASE(pFactory);
return hr;
}