-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOP2Editor.cpp
101 lines (81 loc) · 2.55 KB
/
OP2Editor.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
// OP2Editor.cpp : Implementation of DLL Exports.
// Note: Proxy/Stub Information
// To build a separate proxy/stub DLL,
// run nmake -f OP2Editorps.mk in the project directory.
#include "stdafx.h"
#include "resource.h"
#include <initguid.h>
#include "OP2Editor.h"
#include "OP2Editor_i.c"
#include "CFileStreamReader.h"
#include "CFileStreamWriter.h"
#include "CResourceManager.h"
#include "CResourceManagerFactory.h"
int g_cLocks = 0;
HINSTANCE g_hInstance = NULL;
// DLL Entry Point
extern "C"
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
g_hInstance = hInstance;
DisableThreadLibraryCalls(hInstance);
}
return TRUE; // ok
}
// Used to determine whether the DLL can be unloaded by OLE
STDAPI DllCanUnloadNow(void)
{
if (g_cLocks == 0)
return S_OK;
else
return S_FALSE;
}
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
if(rclsid != CLSID_ResourceManager)
return CLASS_E_CLASSNOTAVAILABLE;
CResourceManagerFactory *pFactory = new CResourceManagerFactory();
if(pFactory == NULL)
return E_OUTOFMEMORY;
// riid is probably IID_IClassFactory.
HRESULT hr = pFactory->QueryInterface(riid, ppv);
pFactory->Release(); // Just in case QueryInterface fails
return hr;
}
// DllRegisterServer - Adds entries to the system registry
STDAPI DllRegisterServer(void)
{
HKEY hSubKey;
TCHAR path[MAX_PATH];
DWORD creationDisposition;
int pathLen;
int retVal;
pathLen = GetModuleFileName(g_hInstance, path, MAX_PATH);
retVal = RegCreateKeyEx(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32"),
0,
TEXT(""),
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hSubKey,
&creationDisposition);
if (retVal != ERROR_SUCCESS)
return HRESULT_FROM_WIN32(retVal);
retVal = RegSetValueEx(hSubKey, TEXT(""), 0, REG_SZ, (BYTE*)path, pathLen);
RegCloseKey(hSubKey);
return HRESULT_FROM_WIN32(retVal);
}
// DllUnregisterServer - Removes entries from the system registry
STDAPI DllUnregisterServer(void)
{
int retVal;
retVal = RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}\\InprocServer32"));
retVal = RegDeleteKey(HKEY_CLASSES_ROOT,
TEXT("CLSID\\{C8DE4CDE-4554-4fe9-8688-A90D91EBCA0B}"));
return HRESULT_FROM_WIN32(retVal);
}