-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDllMain.cpp
140 lines (113 loc) · 2.89 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
#include <Windows.h>
#include <ShlObj.h>
#include "ClassFactory.h"
#include "Resource.h"
HINSTANCE hDllInst = NULL;
LONG cDllRef = 0;
CLSID CLSID_Start = {0x3f6953f0, 0x5359, 0x47fc, {0xbd, 0x99, 0x9f, 0x2c, 0xb9, 0x5a, 0x62, 0xff}};
TCHAR szSetupKey[] = TEXT("Software\\Start");
TCHAR szImsspKey[] = TEXT("Software\\Classes\\CLSID\\{23650F94-13B8-4F39-B2C3-817E6564A756}\\InProcServer32");
TCHAR szStartKey[] = TEXT("Software\\Classes\\CLSID\\{3F6953F0-5359-47FC-BD99-9F2CB95A62FF}\\InprocServer32");
STDAPI_(BOOL) DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
hDllInst = hInstance;
DisableThreadLibraryCalls(hDllInst);
}
return TRUE;
}
STDAPI DllCanUnloadNow()
{
return cDllRef > 0 ? S_FALSE : S_OK;
}
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
HRESULT hr;
CClassFactory *pcf;
*ppv = NULL;
hr = CLASS_E_CLASSNOTAVAILABLE;
if (IsEqualCLSID(CLSID_Start, rclsid))
{
hr = E_OUTOFMEMORY;
pcf = new CClassFactory();
if (pcf)
{
hr = pcf->QueryInterface(riid, ppv);
pcf->Release();
}
}
return hr;
}
STDAPI DllRegisterServer()
{
HRESULT hr;
TCHAR sz[MAX_PATH];
DWORD cb;
LSTATUS ls;
TCHAR *psz;
ICatRegister *pcr;
CATID catid;
hr = E_FAIL;
pcr = NULL;
cb = LoadString(hDllInst, IDS_START, sz, MAX_PATH);
if (!cb)
goto end;
szStartKey[61] = TEXT('\0');
cb *= sizeof(TCHAR);
ls = RegSetKeyValue(HKEY_LOCAL_MACHINE, szStartKey, NULL, REG_SZ, sz, cb);
if (ls != ERROR_SUCCESS)
goto end;
szStartKey[61] = TEXT('\\');
cb = GetModuleFileName(hDllInst, sz, MAX_PATH);
if (!cb)
goto end;
cb *= sizeof(TCHAR);
ls = RegSetKeyValue(HKEY_LOCAL_MACHINE, szStartKey, NULL, REG_SZ, sz, cb);
if (ls != ERROR_SUCCESS)
goto end;
psz = TEXT("ThreadingModel");
lstrcpy(sz, TEXT("Apartment"));
cb = lstrlen(sz) * sizeof(TCHAR);
ls = RegSetKeyValue(HKEY_LOCAL_MACHINE, szStartKey, psz, REG_SZ, sz, cb);
if (ls != ERROR_SUCCESS)
goto end;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL,
CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID *)&pcr);
if (FAILED(hr))
goto end;
catid = CATID_DeskBand;
hr = pcr->RegisterClassImplCategories(CLSID_Start, 1, &catid);
end:
if (pcr)
pcr->Release();
return hr;
}
STDAPI DllUnregisterServer()
{
HRESULT hr;
ICatRegister *pcr;
CATID catid;
LSTATUS ls;
hr = E_FAIL;
pcr = NULL;
hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL,
CLSCTX_INPROC_SERVER, IID_ICatRegister, (LPVOID *)&pcr);
if (FAILED(hr))
goto end;
catid = CATID_DeskBand;
hr = pcr->UnRegisterClassImplCategories(CLSID_Start, 1, &catid);
if (FAILED(hr))
goto end;
szImsspKey[61] = TEXT('\0');
RegDeleteTree(HKEY_CURRENT_USER, szImsspKey);
RegDeleteTree(HKEY_CURRENT_USER, szSetupKey);
szStartKey[61] = TEXT('\0');
ls = RegDeleteTree(HKEY_LOCAL_MACHINE, szStartKey);
if (ls != ERROR_SUCCESS)
hr = E_FAIL;
end:
if (pcr)
pcr->Release();
return hr;
}