1/* -*- Mode: C; tab-width: 4 -*- 2 * 3 * Copyright (c) 2009 Apple Computer, Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 19 20 21 22#include "stdafx.h" 23 24#include "resource.h" 25 26#include "DLLX.h" 27 28#include "dlldatax.h" 29 30#include <DebugServices.h> 31 32 33 34 35 36class CDLLComponentModule : public CAtlDllModuleT< CDLLComponentModule > 37 38{ 39 40public : 41 42 DECLARE_LIBID(LIBID_Bonjour) 43 44 DECLARE_REGISTRY_APPID_RESOURCEID(IDR_DLLX, "{56608F9C-223B-4CB6-813D-85EDCCADFB4B}") 45 46}; 47 48 49 50CDLLComponentModule _AtlModule; 51 52 53 54 55 56#ifdef _MANAGED 57 58#pragma managed(push, off) 59 60#endif 61 62 63 64// DLL Entry Point 65 66extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) 67 68{ 69 70 debug_initialize( kDebugOutputTypeWindowsDebugger ); 71 debug_set_property( kDebugPropertyTagPrintLevel, kDebugLevelVerbose ); 72 73 74 75#ifdef _MERGE_PROXYSTUB 76 77 if (!PrxDllMain(hInstance, dwReason, lpReserved)) 78 79 return FALSE; 80 81#endif 82 83 hInstance; 84 85 return _AtlModule.DllMain(dwReason, lpReserved); 86 87} 88 89 90 91#ifdef _MANAGED 92 93#pragma managed(pop) 94 95#endif 96 97 98 99 100 101 102 103 104 105// Used to determine whether the DLL can be unloaded by OLE 106 107STDAPI DllCanUnloadNow(void) 108 109{ 110 111#ifdef _MERGE_PROXYSTUB 112 113 HRESULT hr = PrxDllCanUnloadNow(); 114 115 if (hr != S_OK) 116 117 return hr; 118 119#endif 120 121 return _AtlModule.DllCanUnloadNow(); 122 123} 124 125 126 127 128 129// Returns a class factory to create an object of the requested type 130 131STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 132 133{ 134 135#ifdef _MERGE_PROXYSTUB 136 137 if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK) 138 139 return S_OK; 140 141#endif 142 143 return _AtlModule.DllGetClassObject(rclsid, riid, ppv); 144 145} 146 147 148 149 150 151// DllRegisterServer - Adds entries to the system registry 152 153STDAPI DllRegisterServer(void) 154 155{ 156 157 // registers object, typelib and all interfaces in typelib 158 159 HRESULT hr = _AtlModule.DllRegisterServer(); 160 161#ifdef _MERGE_PROXYSTUB 162 163 if (FAILED(hr)) 164 165 return hr; 166 167 hr = PrxDllRegisterServer(); 168 169#endif 170 171 return hr; 172 173} 174 175 176 177 178 179// DllUnregisterServer - Removes entries from the system registry 180 181STDAPI DllUnregisterServer(void) 182 183{ 184 185 HRESULT hr = _AtlModule.DllUnregisterServer(); 186 187#ifdef _MERGE_PROXYSTUB 188 189 if (FAILED(hr)) 190 191 return hr; 192 193 hr = PrxDllRegisterServer(); 194 195 if (FAILED(hr)) 196 197 return hr; 198 199 hr = PrxDllUnregisterServer(); 200 201#endif 202 203 return hr; 204 205} 206 207 208 209