atl_module.h

Go to the documentation of this file.
00001 00004 /* 00005 * Copyright © 2000, 2001 Paul Hollingsworth, Michael Geddes 00006 * 00007 * This material is provided "as is", with absolutely no warranty 00008 * expressed or implied. Any use is at your own risk. Permission to 00009 * use or copy this software for any purpose is hereby granted without 00010 * fee, provided the above notices are retained on all copies. 00011 * Permission to modify the code and to distribute modified code is 00012 * granted, provided the above notices are retained, and a notice that 00013 * the code was modified is included with the above copyright notice. 00014 * 00015 * This header is part of comet. 00016 * http://www.lambdasoft.dk/comet 00017 */ 00018 00019 #ifndef COMET_ATL_MODULE_H 00020 #define COMET_ATL_MODULE_H 00021 00022 #include <comet/server.h> 00023 00024 namespace comet { 00028 00040 template<typename ITF, typename BASE = ::IUnknown> struct declspec_comtype 00041 { 00042 static const uuid_t& uuid() { return uuid_t::create_const_reference(__uuidof(ITF)); } 00043 typedef BASE base; 00044 }; 00045 00046 00048 struct empty_typelib 00049 { 00050 typedef nil coclasses; 00051 }; 00052 00053 template<typename COM_SERVER, typename ATL_MODULE = ATL::CComModule> 00054 class atl_module_ex : public ATL_MODULE 00055 { 00056 // ATL will take the responsibility of registering the embedded type library. 00057 public: 00058 HRESULT Init(_ATL_OBJMAP_ENTRY* p, HINSTANCE h, const GUID* plibid = NULL) 00059 { 00060 module().instance(h); 00061 return ATL_MODULE::Init(p, h, plibid); 00062 } 00063 00064 HRESULT RegisterServer(BOOL bRegTypeLib = FALSE, const CLSID* pCLSID = NULL) 00065 { 00066 HRESULT hr = ATL_MODULE::RegisterServer(bRegTypeLib, pCLSID); 00067 if(SUCCEEDED(hr)) 00068 hr = COM_SERVER::DllRegisterServer(); 00069 return hr; 00070 } 00071 00072 HRESULT UnregisterServer(BOOL bUnRegTypeLib, const CLSID* pCLSID = NULL) 00073 { 00074 COM_SERVER::DllUnregisterServer(); 00075 return ATL_MODULE::UnregisterServer(bUnRegTypeLib, pCLSID); 00076 } 00077 00078 HRESULT GetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) 00079 { 00080 HRESULT hr = COM_SERVER::DllGetClassObject( rclsid, riid, ppv); 00081 if( hr == CLASS_E_CLASSNOTAVAILABLE ) 00082 { 00083 hr = ATL_MODULE::GetClassObject(rclsid, riid,ppv); 00084 } 00085 return hr; 00086 } 00087 00088 LONG GetLockCount() 00089 { 00090 return module().rc() + ATL_MODULE::GetLockCount(); 00091 } 00092 }; 00093 00111 template<typename TYPELIB = empty_typelib, typename ATL_MODULE = ATL::CComModule> 00112 class atl_module : public atl_module_ex< com_server<TYPELIB, com_server_traits<NO_EMBEDDED_TLB> >, ATL_MODULE > 00113 { 00114 }; 00116 } // namespace comet 00117 00118 #endif