1 | /* $Id: dllmain.cpp 60865 2016-05-06 14:43:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxC - COM DLL exports and DLL init/term.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #include "VBox/com/defs.h"
|
---|
23 |
|
---|
24 | #include <SessionImpl.h>
|
---|
25 | #include <VirtualBoxClientImpl.h>
|
---|
26 |
|
---|
27 | #include <iprt/initterm.h>
|
---|
28 |
|
---|
29 |
|
---|
30 | /*********************************************************************************************************************************
|
---|
31 | * Global Variables *
|
---|
32 | *********************************************************************************************************************************/
|
---|
33 | static ATL::CComModule *g_pAtlComModule;
|
---|
34 |
|
---|
35 | BEGIN_OBJECT_MAP(ObjectMap)
|
---|
36 | OBJECT_ENTRY(CLSID_Session, Session)
|
---|
37 | OBJECT_ENTRY(CLSID_VirtualBoxClient, VirtualBoxClient)
|
---|
38 | END_OBJECT_MAP()
|
---|
39 |
|
---|
40 |
|
---|
41 | /////////////////////////////////////////////////////////////////////////////
|
---|
42 | // DLL Entry Point
|
---|
43 |
|
---|
44 | extern "C"
|
---|
45 | BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
---|
46 | {
|
---|
47 | if (dwReason == DLL_PROCESS_ATTACH)
|
---|
48 | {
|
---|
49 | // idempotent, so doesn't harm, and needed for COM embedding scenario
|
---|
50 | RTR3InitDll(RTR3INIT_FLAGS_UNOBTRUSIVE);
|
---|
51 |
|
---|
52 | g_pAtlComModule = new(ATL::CComModule);
|
---|
53 | if (!g_pAtlComModule)
|
---|
54 | return FALSE;
|
---|
55 |
|
---|
56 | g_pAtlComModule->Init(ObjectMap, hInstance, &LIBID_VirtualBox);
|
---|
57 | DisableThreadLibraryCalls(hInstance);
|
---|
58 | }
|
---|
59 | else if (dwReason == DLL_PROCESS_DETACH)
|
---|
60 | {
|
---|
61 | if (g_pAtlComModule)
|
---|
62 | {
|
---|
63 | g_pAtlComModule->Term();
|
---|
64 | delete g_pAtlComModule;
|
---|
65 | g_pAtlComModule = NULL;
|
---|
66 | }
|
---|
67 | }
|
---|
68 | return TRUE;
|
---|
69 | }
|
---|
70 |
|
---|
71 | /////////////////////////////////////////////////////////////////////////////
|
---|
72 | // Used to determine whether the DLL can be unloaded by OLE
|
---|
73 |
|
---|
74 | STDAPI DllCanUnloadNow(void)
|
---|
75 | {
|
---|
76 | AssertReturn(g_pAtlComModule, S_OK);
|
---|
77 | return g_pAtlComModule->GetLockCount() == 0 ? S_OK : S_FALSE;
|
---|
78 | }
|
---|
79 |
|
---|
80 | /////////////////////////////////////////////////////////////////////////////
|
---|
81 | // Returns a class factory to create an object of the requested type
|
---|
82 |
|
---|
83 | STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
---|
84 | {
|
---|
85 | AssertReturn(g_pAtlComModule, E_UNEXPECTED);
|
---|
86 | return g_pAtlComModule->GetClassObject(rclsid, riid, ppv);
|
---|
87 | }
|
---|
88 |
|
---|
89 | /////////////////////////////////////////////////////////////////////////////
|
---|
90 | // DllRegisterServer - Adds entries to the system registry
|
---|
91 |
|
---|
92 | STDAPI DllRegisterServer(void)
|
---|
93 | {
|
---|
94 | #ifndef VBOX_WITH_MIDL_PROXY_STUB
|
---|
95 | // registers object, typelib and all interfaces in typelib
|
---|
96 | AssertReturn(g_pAtlComModule, E_UNEXPECTED);
|
---|
97 | return g_pAtlComModule->RegisterServer(TRUE);
|
---|
98 | #else
|
---|
99 | return S_OK; /* VBoxProxyStub does all the work, no need to duplicate it here. */
|
---|
100 | #endif
|
---|
101 | }
|
---|
102 |
|
---|
103 | /////////////////////////////////////////////////////////////////////////////
|
---|
104 | // DllUnregisterServer - Removes entries from the system registry
|
---|
105 |
|
---|
106 | STDAPI DllUnregisterServer(void)
|
---|
107 | {
|
---|
108 | #ifndef VBOX_WITH_MIDL_PROXY_STUB
|
---|
109 | AssertReturn(g_pAtlComModule, E_UNEXPECTED);
|
---|
110 | HRESULT hrc = g_pAtlComModule->UnregisterServer(TRUE);
|
---|
111 | return hrc;
|
---|
112 | #else
|
---|
113 | return S_OK; /* VBoxProxyStub does all the work, no need to duplicate it here. */
|
---|
114 | #endif
|
---|
115 | }
|
---|
116 |
|
---|