2010-11-24 13:13:28 +01:00
|
|
|
/*
|
|
|
|
* 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 <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define ATL_INITGUID
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winnls.h"
|
2010-12-08 13:18:45 +01:00
|
|
|
#include "ole2.h"
|
2010-11-24 13:13:28 +01:00
|
|
|
#include "rpcproxy.h"
|
|
|
|
#include "atliface.h"
|
|
|
|
|
2021-04-30 13:40:11 +02:00
|
|
|
static inline void *image_base(void)
|
|
|
|
{
|
2021-12-27 15:01:47 +01:00
|
|
|
#ifdef __WINE_PE_BUILD
|
2021-04-30 13:40:11 +02:00
|
|
|
extern IMAGE_DOS_HEADER __ImageBase;
|
|
|
|
return (void *)&__ImageBase;
|
|
|
|
#else
|
|
|
|
extern IMAGE_NT_HEADERS __wine_spec_nt_header;
|
|
|
|
return (void *)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-21 11:12:37 +01:00
|
|
|
static const WCHAR atl100W[] = {'a','t','l','1','0','0','.','d','l','l',0};
|
2010-11-24 13:13:28 +01:00
|
|
|
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};
|
2021-04-09 20:27:06 +02:00
|
|
|
static const WCHAR systemrootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
|
2010-11-24 13:13:28 +01:00
|
|
|
|
|
|
|
struct reg_info
|
|
|
|
{
|
|
|
|
IRegistrar *registrar;
|
|
|
|
BOOL do_register;
|
|
|
|
HRESULT result;
|
|
|
|
};
|
|
|
|
|
2012-11-21 11:12:37 +01:00
|
|
|
static HMODULE atl100;
|
|
|
|
static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
|
2010-11-24 13:13:28 +01:00
|
|
|
|
|
|
|
static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
|
|
|
|
{
|
2012-11-21 11:12:37 +01:00
|
|
|
if (!pAtlCreateRegistrar)
|
2010-11-24 13:13:28 +01:00
|
|
|
{
|
2012-11-21 11:12:37 +01:00
|
|
|
if (!(atl100 = LoadLibraryW( atl100W )) ||
|
|
|
|
!(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
|
2010-11-24 13:13:28 +01:00
|
|
|
{
|
|
|
|
info->result = E_NOINTERFACE;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-21 11:12:37 +01:00
|
|
|
info->result = pAtlCreateRegistrar( &info->registrar );
|
2010-11-24 13:13:28 +01:00
|
|
|
if (SUCCEEDED( info->result ))
|
|
|
|
{
|
|
|
|
WCHAR str[MAX_PATH];
|
|
|
|
|
|
|
|
GetModuleFileNameW( inst, str, MAX_PATH );
|
|
|
|
IRegistrar_AddReplacement( info->registrar, moduleW, str );
|
2021-04-09 20:27:06 +02:00
|
|
|
GetEnvironmentVariableW( systemrootW, str, MAX_PATH );
|
|
|
|
IRegistrar_AddReplacement( info->registrar, systemrootW, str );
|
2010-11-24 13:13:28 +01:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-04-30 13:40:11 +02:00
|
|
|
HRESULT __cdecl __wine_register_resources(void)
|
2010-11-24 13:13:28 +01:00
|
|
|
{
|
|
|
|
struct reg_info info;
|
|
|
|
|
|
|
|
info.registrar = NULL;
|
|
|
|
info.do_register = TRUE;
|
|
|
|
info.result = S_OK;
|
2021-04-30 13:40:11 +02:00
|
|
|
EnumResourceNamesW( image_base(), regtypeW, register_resource, (LONG_PTR)&info );
|
2010-11-24 13:13:28 +01:00
|
|
|
if (info.registrar) IRegistrar_Release( info.registrar );
|
|
|
|
return info.result;
|
|
|
|
}
|
|
|
|
|
2021-04-30 13:40:11 +02:00
|
|
|
HRESULT __cdecl __wine_unregister_resources(void)
|
2010-11-24 13:13:28 +01:00
|
|
|
{
|
|
|
|
struct reg_info info;
|
|
|
|
|
|
|
|
info.registrar = NULL;
|
|
|
|
info.do_register = FALSE;
|
|
|
|
info.result = S_OK;
|
2021-04-30 13:40:11 +02:00
|
|
|
EnumResourceNamesW( image_base(), regtypeW, register_resource, (LONG_PTR)&info );
|
2010-11-24 13:13:28 +01:00
|
|
|
if (info.registrar) IRegistrar_Release( info.registrar );
|
|
|
|
return info.result;
|
|
|
|
}
|