1 /***************************************************************************
2  *                                                                         *
3  *    LIBDSK: General floppy and diskimage access library                  *
4  *    Copyright (C) 2005  John Elliott <seasip.webmaster@gmail.com>            *
5  *                                                                         *
6  *    This library is free software; you can redistribute it and/or        *
7  *    modify it under the terms of the GNU Library General Public          *
8  *    License as published by the Free Software Foundation; either         *
9  *    version 2 of the License, or (at your option) any later version.     *
10  *                                                                         *
11  *    This library is distributed in the hope that it will be useful,      *
12  *    but WITHOUT ANY WARRANTY; without even the implied warranty of       *
13  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    *
14  *    Library General Public License for more details.                     *
15  *                                                                         *
16  *    You should have received a copy of the GNU Library General Public    *
17  *    License along with this library; if not, write to the Free           *
18  *    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,      *
19  *    MA 02111-1307, USA                                                   *
20  *                                                                         *
21  ***************************************************************************/
22 
23 
24 // Note: Proxy/Stub Information
25 //      To merge the proxy/stub code into the object DLL, add the file
26 //      dlldatax.c to the project.  Make sure precompiled headers
27 //      are turned off for this file, and add _MERGE_PROXYSTUB to the
28 //      defines for the project.
29 //
30 //      If you are not running WinNT4.0 or Win95 with DCOM, then you
31 //      need to remove the following define from dlldatax.c
32 //      #define _WIN32_WINNT 0x0400
33 //
34 //      Further, if you are running MIDL without /Oicf switch, you also
35 //      need to remove the following define from dlldatax.c.
36 //      #define USE_STUBLESS_PROXY
37 //
38 //      Modify the custom build rule for atlibdsk.idl by adding the following
39 //      files to the Outputs.
40 //          atlibdsk_p.c
41 //          dlldata.c
42 //      To build a separate proxy/stub DLL,
43 //      run nmake -f atlibdskps.mk in the project directory.
44 
45 #include "stdafx.h"
46 #include "resource.h"
47 #include <initguid.h>
48 #include "atlibdsk.h"
49 #include "dlldatax.h"
50 
51 #include "atlibdsk_i.c"
52 #include "Library.h"
53 #include "Disk.h"
54 #include "Geometry.h"
55 #include "Reporter.h"
56 
57 #ifdef _MERGE_PROXYSTUB
58 extern "C" HINSTANCE hProxyDll;
59 #endif
60 
61 CComModule _Module;
62 
63 BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Library,CLibrary)64 OBJECT_ENTRY(CLSID_Library, CLibrary)
65 OBJECT_ENTRY(CLSID_Disk, CDisk)
66 OBJECT_ENTRY(CLSID_Geometry, CGeometry)
67 OBJECT_ENTRY(CLSID_Reporter, CReporter)
68 END_OBJECT_MAP()
69 
70 /////////////////////////////////////////////////////////////////////////////
71 // DLL Entry Point
72 
73 extern "C"
74 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
75 {
76     lpReserved;
77 #ifdef _MERGE_PROXYSTUB
78     if (!PrxDllMain(hInstance, dwReason, lpReserved))
79         return FALSE;
80 #endif
81     if (dwReason == DLL_PROCESS_ATTACH)
82     {
83         _Module.Init(ObjectMap, hInstance, &LIBID_LIBDSK);
84         DisableThreadLibraryCalls(hInstance);
85     }
86     else if (dwReason == DLL_PROCESS_DETACH)
87         _Module.Term();
88     return TRUE;    // ok
89 }
90 
91 /////////////////////////////////////////////////////////////////////////////
92 // Used to determine whether the DLL can be unloaded by OLE
93 
DllCanUnloadNow(void)94 STDAPI DllCanUnloadNow(void)
95 {
96 #ifdef _MERGE_PROXYSTUB
97     if (PrxDllCanUnloadNow() != S_OK)
98         return S_FALSE;
99 #endif
100     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
101 }
102 
103 /////////////////////////////////////////////////////////////////////////////
104 // Returns a class factory to create an object of the requested type
105 
DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID * ppv)106 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
107 {
108 #ifdef _MERGE_PROXYSTUB
109     if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
110         return S_OK;
111 #endif
112     return _Module.GetClassObject(rclsid, riid, ppv);
113 }
114 
115 /////////////////////////////////////////////////////////////////////////////
116 // DllRegisterServer - Adds entries to the system registry
117 
DllRegisterServer(void)118 STDAPI DllRegisterServer(void)
119 {
120 #ifdef _MERGE_PROXYSTUB
121     HRESULT hRes = PrxDllRegisterServer();
122     if (FAILED(hRes))
123         return hRes;
124 #endif
125     // registers object, typelib and all interfaces in typelib
126     return _Module.RegisterServer(TRUE);
127 }
128 
129 /////////////////////////////////////////////////////////////////////////////
130 // DllUnregisterServer - Removes entries from the system registry
131 
DllUnregisterServer(void)132 STDAPI DllUnregisterServer(void)
133 {
134 #ifdef _MERGE_PROXYSTUB
135     PrxDllUnregisterServer();
136 #endif
137     return _Module.UnregisterServer(TRUE);
138 }
139 
140 
141