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_hinst = 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* pcf = new CClassFactory;
|
---|
38 | if (pcf)
|
---|
39 | {
|
---|
40 | hr = pcf->QueryInterface(riid, ppv);
|
---|
41 | pcf->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_hinst = 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 | /* DLL entry point */
|
---|
95 | STDAPI DllCanUnloadNow()
|
---|
96 | {
|
---|
97 | HRESULT hr;
|
---|
98 |
|
---|
99 | if (g_cRef > 0)
|
---|
100 | {
|
---|
101 | hr = S_FALSE; /* Cocreated objects still exist, don't unload */
|
---|
102 | }
|
---|
103 | else
|
---|
104 | {
|
---|
105 | hr = S_OK; /* Refcount is zero, ok to unload */
|
---|
106 | }
|
---|
107 |
|
---|
108 | /* Never terminate the runtime! */
|
---|
109 | return hr;
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv)
|
---|
114 | {
|
---|
115 | return CClassFactory_CreateInstance(rclsid, riid, ppv);
|
---|
116 | }
|
---|
117 |
|
---|