1 | //
|
---|
2 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
---|
3 | // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
|
---|
4 | // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
---|
5 | // PARTICULAR PURPOSE.
|
---|
6 | //
|
---|
7 | // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
|
---|
8 | //
|
---|
9 | // Standard dll required functions and class factory implementation.
|
---|
10 | //
|
---|
11 | // Modifications (c) 2009-2010 Oracle Corporation
|
---|
12 | //
|
---|
13 |
|
---|
14 | /*******************************************************************************
|
---|
15 | * Header Files *
|
---|
16 | *******************************************************************************/
|
---|
17 | #include <windows.h>
|
---|
18 |
|
---|
19 | #include <VBox/VBoxGuestLib.h>
|
---|
20 |
|
---|
21 | #include "dll.h"
|
---|
22 | #include "guid.h"
|
---|
23 |
|
---|
24 |
|
---|
25 | /*******************************************************************************
|
---|
26 | * Global Variables *
|
---|
27 | *******************************************************************************/
|
---|
28 | static LONG g_cRef = 0; /* Global DLL reference count. */
|
---|
29 | HINSTANCE g_hDllInst = NULL; /* Global DLL hinstance. */
|
---|
30 |
|
---|
31 |
|
---|
32 | HRESULT CClassFactory_CreateInstance(REFCLSID rclsid, REFIID riid, void** ppv)
|
---|
33 | {
|
---|
34 | HRESULT hr;
|
---|
35 | if (CLSID_VBoxCredProvider == rclsid)
|
---|
36 | {
|
---|
37 | CClassFactory* pClassFactory = new CClassFactory;
|
---|
38 | if (pClassFactory)
|
---|
39 | {
|
---|
40 | hr = pClassFactory->QueryInterface(riid, ppv);
|
---|
41 | pClassFactory->Release();
|
---|
42 | }
|
---|
43 | else
|
---|
44 | {
|
---|
45 | hr = E_OUTOFMEMORY;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | else
|
---|
49 | {
|
---|
50 | hr = CLASS_E_CLASSNOTAVAILABLE;
|
---|
51 | }
|
---|
52 | return hr;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | BOOL WINAPI DllMain(HINSTANCE hinstDll,
|
---|
57 | DWORD dwReason,
|
---|
58 | LPVOID pReserved)
|
---|
59 | {
|
---|
60 | UNREFERENCED_PARAMETER(pReserved);
|
---|
61 |
|
---|
62 | switch (dwReason)
|
---|
63 | {
|
---|
64 | case DLL_PROCESS_ATTACH:
|
---|
65 |
|
---|
66 | DisableThreadLibraryCalls(hinstDll);
|
---|
67 | break;
|
---|
68 |
|
---|
69 | case DLL_PROCESS_DETACH:
|
---|
70 | break;
|
---|
71 |
|
---|
72 | case DLL_THREAD_ATTACH:
|
---|
73 | case DLL_THREAD_DETACH:
|
---|
74 | break;
|
---|
75 | }
|
---|
76 |
|
---|
77 | g_hDllInst = hinstDll;
|
---|
78 | return TRUE;
|
---|
79 | }
|
---|
80 |
|
---|
81 |
|
---|
82 | LONG DllAddRef()
|
---|
83 | {
|
---|
84 | return InterlockedIncrement(&g_cRef);
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 | LONG DllRelease()
|
---|
89 | {
|
---|
90 | return InterlockedDecrement(&g_cRef);
|
---|
91 | }
|
---|
92 |
|
---|
93 |
|
---|
94 | LONG DllGetRefCount()
|
---|
95 | {
|
---|
96 | return g_cRef;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /* DLL entry point. */
|
---|
101 | STDAPI DllCanUnloadNow()
|
---|
102 | {
|
---|
103 | HRESULT hr;
|
---|
104 |
|
---|
105 | if (g_cRef > 0)
|
---|
106 | {
|
---|
107 | hr = S_FALSE; /* Cocreated objects still exist, don't unload */
|
---|
108 | }
|
---|
109 | else
|
---|
110 | {
|
---|
111 | hr = S_OK; /* Refcount is zero, ok to unload */
|
---|
112 | }
|
---|
113 |
|
---|
114 | /* Never terminate the runtime! */
|
---|
115 | return hr;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)
|
---|
120 | {
|
---|
121 | return CClassFactory_CreateInstance(rclsid, riid, ppv);
|
---|
122 | }
|
---|
123 |
|
---|