Commit 4d966be6 authored by Alexandre Julliard's avatar Alexandre Julliard

winecrt0: Add a generic mechanism for dll registration through IRegistrar.

parent cd4b9c11
......@@ -12,6 +12,7 @@ C_SRCS = \
exe_wentry.c \
exe_wmain.c \
init.c \
register.c \
stub.c
@MAKE_IMPLIB_RULES@
/*
* Support functions for Wine dll registrations
*
* Copyright (c) 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
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include <stdarg.h>
#define COBJMACROS
#define ATL_INITGUID
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
#include "objbase.h"
#include "rpcproxy.h"
#include "atliface.h"
static const WCHAR ole32W[] = {'o','l','e','3','2','.','d','l','l',0};
static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
static const WCHAR clsidW[] = {'C','L','S','I','D','_','P','S','F','a','c','t','o','r','y','B','u','f','f','e','r',0};
struct reg_info
{
IRegistrar *registrar;
const CLSID *clsid;
BOOL do_register;
BOOL uninit;
HRESULT result;
};
static HMODULE ole32;
static HRESULT (WINAPI *pCoInitialize)(LPVOID);
static void (WINAPI *pCoUninitialize)(void);
static HRESULT (WINAPI *pCoCreateInstance)(REFCLSID,LPUNKNOWN,DWORD,REFIID,LPVOID*);
static INT (WINAPI *pStringFromGUID2)(REFGUID,LPOLESTR,INT);
static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
{
if (!ole32)
{
if (!(ole32 = LoadLibraryW( ole32W )) ||
!(pCoInitialize = (void *)GetProcAddress( ole32, "CoInitialize" )) ||
!(pCoUninitialize = (void *)GetProcAddress( ole32, "CoUninitialize" )) ||
!(pCoCreateInstance = (void *)GetProcAddress( ole32, "CoCreateInstance" )) ||
!(pStringFromGUID2 = (void *)GetProcAddress( ole32, "StringFromGUID2" )))
{
info->result = E_NOINTERFACE;
return NULL;
}
}
info->uninit = SUCCEEDED( pCoInitialize( NULL ));
info->result = pCoCreateInstance( &CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER,
&IID_IRegistrar, (void **)&info->registrar );
if (SUCCEEDED( info->result ))
{
WCHAR str[MAX_PATH];
GetModuleFileNameW( inst, str, MAX_PATH );
IRegistrar_AddReplacement( info->registrar, moduleW, str );
if (info->clsid)
{
pStringFromGUID2( info->clsid, str, MAX_PATH );
IRegistrar_AddReplacement( info->registrar, clsidW, 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);
}
HRESULT __wine_register_resources( HMODULE module, const CLSID *clsid )
{
struct reg_info info;
info.registrar = NULL;
info.clsid = clsid;
info.do_register = TRUE;
info.uninit = FALSE;
info.result = S_OK;
EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
if (info.registrar) IRegistrar_Release( info.registrar );
if (info.uninit) pCoUninitialize();
return info.result;
}
HRESULT __wine_unregister_resources( HMODULE module, const CLSID *clsid )
{
struct reg_info info;
info.registrar = NULL;
info.clsid = clsid;
info.do_register = FALSE;
info.uninit = FALSE;
info.result = S_OK;
EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
if (info.registrar) IRegistrar_Release( info.registrar );
if (info.uninit) pCoUninitialize();
return info.result;
}
......@@ -203,6 +203,9 @@ RPCRTAPI HRESULT RPC_ENTRY
RPCRTAPI HRESULT RPC_ENTRY
NdrDllUnregisterProxy( HMODULE hDll, const ProxyFileInfo **pProxyFileList, const CLSID *pclsid );
HRESULT __wine_register_resources( HMODULE module, const CLSID *clsid ) DECLSPEC_HIDDEN;
HRESULT __wine_unregister_resources( HMODULE module, const CLSID *clsid ) DECLSPEC_HIDDEN;
#define CSTDSTUBBUFFERRELEASE(pFactory) \
ULONG WINAPI CStdStubBuffer_Release(IRpcStubBuffer *This) \
{ return NdrCStdStubBuffer_Release(This, (IPSFactoryBuffer *)pFactory); }
......@@ -285,6 +288,26 @@ ULONG WINAPI CStdStubBuffer2_Release(IRpcStubBuffer *This) \
# define DLLCANUNLOADNOW_ENTRY DllCanUnloadNow
#endif
#ifdef WINE_REGISTER_DLL
#define WINE_DO_REGISTER_DLL(pfl, clsid) \
HRESULT hr = NdrDllRegisterProxy( hProxyDll, (pfl), (clsid) ); \
if (SUCCEEDED(hr)) hr = __wine_register_resources( hProxyDll, clsid ); \
return hr
#define WINE_DO_UNREGISTER_DLL(pfl, clsid) \
HRESULT hr = __wine_unregister_resources( hProxyDll, clsid ); \
if (SUCCEEDED(hr)) hr = NdrDllUnregisterProxy( hProxyDll, (pfl), (clsid) ); \
return hr
#else
#define WINE_DO_REGISTER_DLL(pfl, clsid) return NdrDllRegisterProxy( hProxyDll, (pfl), (clsid) )
#define WINE_DO_UNREGISTER_DLL(pfl, clsid) return NdrDllUnregisterProxy( hProxyDll, (pfl), (clsid) )
#endif
#define DLLDATA_GETPROXYDLLINFO(pfl, rclsid) \
void RPC_ENTRY GetProxyDllInfo(const ProxyFileInfo ***ppProxyFileInfo, \
const CLSID **ppClsid) DECLSPEC_HIDDEN; \
......@@ -329,16 +352,16 @@ ULONG WINAPI CStdStubBuffer2_Release(IRpcStubBuffer *This) \
HRESULT WINAPI DLLREGISTERSERVER_ENTRY(void) DECLSPEC_HIDDEN; \
HRESULT WINAPI DLLREGISTERSERVER_ENTRY(void) \
{ \
return NdrDllRegisterProxy(hProxyDll, (pfl), (factory_clsid)); \
WINE_DO_REGISTER_DLL( (pfl), (factory_clsid) ); \
} \
\
HRESULT WINAPI DLLUNREGISTERSERVER_ENTRY(void) DECLSPEC_HIDDEN; \
HRESULT WINAPI DLLUNREGISTERSERVER_ENTRY(void) \
{ \
return NdrDllUnregisterProxy(hProxyDll, (pfl), (factory_clsid)); \
WINE_DO_UNREGISTER_DLL( (pfl), (factory_clsid) ); \
}
#ifdef REGISTER_PROXY_DLL
#if defined(REGISTER_PROXY_DLL) || defined(WINE_REGISTER_DLL)
# define DLLREGISTRY_ROUTINES(pfl, factory_clsid) \
REGISTER_PROXY_DLL_ROUTINES(pfl, factory_clsid)
#else
......
......@@ -2484,12 +2484,12 @@ HKLM,%CurrentVersion%\Telephony\Country List\998,"SameAreaRule",,"G"
[RegisterDllsSection]
;;some dlls have to be registered first
11,,ole32.dll,1
11,,atl.dll,1
11,,oleaut32.dll,1
11,,shell32.dll,1
11,,actxprxy.dll,1
11,,amstream.dll,1
11,,atl.dll,1
11,,avifil32.dll,1
11,,browseui.dll,1
11,,comctl32.dll,2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment