From 48216541fdf434df4c494be188485dd164273b0b Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 3 Dec 2010 20:23:54 +0100 Subject: [PATCH] atl: Generate the class registration and use a copy of the standard winecrt0 mechanism. --- dlls/atl/Makefile.in | 2 +- dlls/atl/atl.rgs | 17 ------ dlls/atl/{rsrc.rc => atl_classes.idl} | 13 +++- dlls/atl/registrar.c | 87 +++++++++++++++++++++------ 4 files changed, 81 insertions(+), 38 deletions(-) delete mode 100644 dlls/atl/atl.rgs rename dlls/atl/{rsrc.rc => atl_classes.idl} (75%) diff --git a/dlls/atl/Makefile.in b/dlls/atl/Makefile.in index a631ed82de0..fd7d629a5c6 100644 --- a/dlls/atl/Makefile.in +++ b/dlls/atl/Makefile.in @@ -7,6 +7,6 @@ C_SRCS = \ atl_main.c \ registrar.c -RC_SRCS = rsrc.rc +IDL_R_SRCS = atl_classes.idl @MAKE_DLL_RULES@ diff --git a/dlls/atl/atl.rgs b/dlls/atl/atl.rgs deleted file mode 100644 index ee432497f78..00000000000 --- a/dlls/atl/atl.rgs +++ /dev/null @@ -1,17 +0,0 @@ -HKCR -{ - ATL.Registrar = s 'Registrar Class' - { - CLSID = s '%CLSID_Registrar%' - } - NoRemove CLSID { - ForceRemove '%CLSID_Registrar%' = s 'Registrar Class' - { - ProgID = s 'ATL.Registrar' - InprocServer32 = s '%MODULE%' - { - val ThreadingModel = s 'Both' - } - } - } -} diff --git a/dlls/atl/rsrc.rc b/dlls/atl/atl_classes.idl similarity index 75% rename from dlls/atl/rsrc.rc rename to dlls/atl/atl_classes.idl index c55953352c9..90605b41a40 100644 --- a/dlls/atl/rsrc.rc +++ b/dlls/atl/atl_classes.idl @@ -1,5 +1,7 @@ /* - * Copyright 2005 Jacek Caban + * COM Classes for ATL + * + * Copyright 2010 Alexandre Julliard * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -16,5 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -/* @makedep: atl.rgs */ -101 REGISTRY atl.rgs +[ + helpstring("Registrar Class"), + progid("ATL.Registrar"), + threading(both), + uuid(44ec053a-400f-11d0-9dcd-00a0c90391d3) +] +coclass Registrar { interface IRegistrar; } diff --git a/dlls/atl/registrar.c b/dlls/atl/registrar.c index 21888506a05..dad2eafa397 100644 --- a/dlls/atl/registrar.c +++ b/dlls/atl/registrar.c @@ -789,6 +789,58 @@ HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, LPVOID *ppvObject) extern HINSTANCE hInst; +/* this is a copy of the winecrt0 registration code that creates the registrar directly, */ +/* since we can't do it through ole32 until it has been registered */ + +struct reg_info +{ + IRegistrar *registrar; + BOOL do_register; + HRESULT result; +}; + +static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info ) +{ + info->result = Registrar_create( NULL, &IID_IRegistrar, (void**)&info->registrar ); + if (SUCCEEDED( info->result )) + { + static const WCHAR moduleW[] = {'M','O','D','U','L','E',0}; + WCHAR str[MAX_PATH]; + + GetModuleFileNameW( hInst, str, MAX_PATH ); + IRegistrar_AddReplacement( info->registrar, moduleW, str ); + } + return info->registrar; +} + +static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg ) +{ + struct reg_info *info = (struct reg_info *)arg; + WCHAR *buffer; + HRSRC rsrc = FindResourceW( module, name, type ); + char *str = LoadResource( module, rsrc ); + DWORD lenW, lenA = SizeofResource( module, rsrc ); + + if (!str) return FALSE; + if (!info->registrar && !create_registrar( module, info )) return FALSE; + lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1; + if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) ))) + { + info->result = E_OUTOFMEMORY; + return FALSE; + } + MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW ); + buffer[lenW - 1] = 0; + + if (info->do_register) + info->result = IRegistrar_StringRegister( info->registrar, buffer ); + else + info->result = IRegistrar_StringUnregister( info->registrar, buffer ); + + HeapFree( GetProcessHeap(), 0, buffer ); + return SUCCEEDED(info->result); +} + static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll, LPCOLESTR wszId, BOOL do_register, const struct _ATL_REGMAP_ENTRY* pMapEntries) @@ -820,19 +872,6 @@ static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll, return hres; } -static HRESULT do_register_server(BOOL do_register) -{ - static const WCHAR CLSID_RegistrarW[] = - {'C','L','S','I','D','_','R','e','g','i','s','t','r','a','r',0}; - static const WCHAR atl_dllW[] = {'a','t','l','.','d','l','l',0}; - - WCHAR clsid_str[40]; - const struct _ATL_REGMAP_ENTRY reg_map[] = {{CLSID_RegistrarW, clsid_str}, {NULL,NULL}}; - - StringFromGUID2(&CLSID_Registrar, clsid_str, sizeof(clsid_str)/sizeof(WCHAR)); - return do_register_dll_server(NULL, atl_dllW, MAKEINTRESOURCEW(101), do_register, reg_map); -} - /*********************************************************************** * AtlModuleUpdateRegistryFromResourceD [ATL.@] * @@ -858,13 +897,21 @@ HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR return do_register_dll_server(pReg, module_name, lpszRes, bRegister, pMapEntries); } +static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0}; + /*********************************************************************** * DllRegisterServer (ATL.@) */ HRESULT WINAPI DllRegisterServer(void) { - TRACE("\n"); - return do_register_server(TRUE); + struct reg_info info; + + info.registrar = NULL; + info.do_register = TRUE; + info.result = S_OK; + EnumResourceNamesW( hInst, regtypeW, register_resource, (LONG_PTR)&info ); + if (info.registrar) IRegistrar_Release( info.registrar ); + return info.result; } /*********************************************************************** @@ -872,8 +919,14 @@ HRESULT WINAPI DllRegisterServer(void) */ HRESULT WINAPI DllUnregisterServer(void) { - TRACE("\n"); - return do_register_server(FALSE); + struct reg_info info; + + info.registrar = NULL; + info.do_register = FALSE; + info.result = S_OK; + EnumResourceNamesW( hInst, regtypeW, register_resource, (LONG_PTR)&info ); + if (info.registrar) IRegistrar_Release( info.registrar ); + return info.result; } /***********************************************************************