Alexandre Julliard : atl: Generate the class registration and use a copy of the standard winecrt0 mechanism .
Alexandre Julliard
julliard at winehq.org
Sun Dec 5 12:10:04 CST 2010
Module: wine
Branch: master
Commit: 48216541fdf434df4c494be188485dd164273b0b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=48216541fdf434df4c494be188485dd164273b0b
Author: Alexandre Julliard <julliard at winehq.org>
Date: Fri Dec 3 20:23:54 2010 +0100
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(-)
diff --git a/dlls/atl/Makefile.in b/dlls/atl/Makefile.in
index a631ed8..fd7d629 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 ee43249..0000000
--- 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 c559533..90605b4 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 2188850..dad2eaf 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;
}
/***********************************************************************
More information about the wine-cvs
mailing list