1 | // Server.cpp : Implementation of DLL Exports. |
---|
2 | |
---|
3 | |
---|
4 | #include "stdafx.h" |
---|
5 | #include "resource.h" |
---|
6 | #include "Server_i.h" |
---|
7 | #include "dllmain.h" |
---|
8 | |
---|
9 | |
---|
10 | using namespace ATL; |
---|
11 | |
---|
12 | // Used to determine whether the DLL can be unloaded by OLE. |
---|
13 | _Use_decl_annotations_ |
---|
14 | STDAPI DllCanUnloadNow(void) |
---|
15 | { |
---|
16 | return _AtlModule.DllCanUnloadNow(); |
---|
17 | } |
---|
18 | |
---|
19 | // Returns a class factory to create an object of the requested type. |
---|
20 | _Use_decl_annotations_ |
---|
21 | STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv) |
---|
22 | { |
---|
23 | return _AtlModule.DllGetClassObject(rclsid, riid, ppv); |
---|
24 | } |
---|
25 | |
---|
26 | // DllRegisterServer - Adds entries to the system registry. |
---|
27 | _Use_decl_annotations_ |
---|
28 | STDAPI DllRegisterServer(void) |
---|
29 | { |
---|
30 | // registers object, typelib and all interfaces in typelib |
---|
31 | HRESULT hr = _AtlModule.DllRegisterServer(); |
---|
32 | return hr; |
---|
33 | } |
---|
34 | |
---|
35 | // DllUnregisterServer - Removes entries from the system registry. |
---|
36 | _Use_decl_annotations_ |
---|
37 | STDAPI DllUnregisterServer(void) |
---|
38 | { |
---|
39 | HRESULT hr = _AtlModule.DllUnregisterServer(); |
---|
40 | return hr; |
---|
41 | } |
---|
42 | |
---|
43 | // DllInstall - Adds/Removes entries to the system registry per user per machine. |
---|
44 | STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine) |
---|
45 | { |
---|
46 | HRESULT hr = E_FAIL; |
---|
47 | static const wchar_t szUserSwitch[] = L"user"; |
---|
48 | |
---|
49 | if (pszCmdLine != NULL) |
---|
50 | { |
---|
51 | if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0) |
---|
52 | { |
---|
53 | ATL::AtlSetPerUserRegistration(true); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | if (bInstall) |
---|
58 | { |
---|
59 | hr = DllRegisterServer(); |
---|
60 | if (FAILED(hr)) |
---|
61 | { |
---|
62 | DllUnregisterServer(); |
---|
63 | } |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | hr = DllUnregisterServer(); |
---|
68 | } |
---|
69 | |
---|
70 | return hr; |
---|
71 | } |
---|
72 | |
---|
73 | |
---|