ReactOS 0.4.16-dev-1946-g52006dd
register.c
Go to the documentation of this file.
1/*
2 * Support functions for Wine dll registrations
3 *
4 * Copyright (c) 2010 Alexandre Julliard
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include "config.h"
22#include <stdarg.h>
23
24#define COBJMACROS
25#define ATL_INITGUID
26#include "windef.h"
27#include "winbase.h"
28#include "winnls.h"
29#include "ole2.h"
30#include "rpcproxy.h"
31#include "atliface.h"
32
33static inline void *image_base(void)
34{
35#if defined(__MINGW32__) || defined(_MSC_VER)
37 return (void *)&__ImageBase;
38#else
39 extern IMAGE_NT_HEADERS __wine_spec_nt_header;
40 return (void *)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
41#endif
42}
43
44static const WCHAR atl100W[] = {'a','t','l','1','0','0','.','d','l','l',0};
45static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
46static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
47static const WCHAR systemrootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
48
50{
54};
55
57static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
58
60{
61 if (!pAtlCreateRegistrar)
62 {
63 if (!(atl100 = LoadLibraryW( atl100W )) ||
64 !(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
65 {
66 info->result = E_NOINTERFACE;
67 return NULL;
68 }
69 }
70
71 info->result = pAtlCreateRegistrar( &info->registrar );
72 if (SUCCEEDED( info->result ))
73 {
75
77 IRegistrar_AddReplacement( info->registrar, moduleW, str );
79 IRegistrar_AddReplacement( info->registrar, systemrootW, str );
80 }
81 return info->registrar;
82}
83
85{
86 struct reg_info *info = (struct reg_info *)arg;
88 HRSRC rsrc = FindResourceW( module, name, type );
89 char *str = LoadResource( module, rsrc );
90 DWORD lenW, lenA = SizeofResource( module, rsrc );
91
92 if (!str) return FALSE;
93 if (!info->registrar && !create_registrar( module, info )) return FALSE;
94 lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
95 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
96 {
97 info->result = E_OUTOFMEMORY;
98 return FALSE;
99 }
100 MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
101 buffer[lenW - 1] = 0;
102
103 if (info->do_register)
104 info->result = IRegistrar_StringRegister( info->registrar, buffer );
105 else
106 info->result = IRegistrar_StringUnregister( info->registrar, buffer );
107
109 return SUCCEEDED(info->result);
110}
111
113{
114 struct reg_info info;
115
116 info.registrar = NULL;
117 info.do_register = TRUE;
118 info.result = S_OK;
120 if (info.registrar) IRegistrar_Release( info.registrar );
121 return info.result;
122}
123
125{
126 struct reg_info info;
127
128 info.registrar = NULL;
129 info.do_register = FALSE;
130 info.result = S_OK;
132 if (info.registrar) IRegistrar_Release( info.registrar );
133 return info.result;
134}
135
136// FIXME: Workaround until all modules use the new prototype
137// See rpcproxy.h
139{
140 struct reg_info info;
141
142 info.registrar = NULL;
143 info.do_register = TRUE;
144 info.result = S_OK;
146 if (info.registrar) IRegistrar_Release( info.registrar );
147 return info.result;
148}
149
151{
152 struct reg_info info;
153
154 info.registrar = NULL;
155 info.do_register = FALSE;
156 info.result = S_OK;
158 if (info.registrar) IRegistrar_Release( info.registrar );
159 return info.result;
160}
#define __cdecl
Definition: accygwin.h:79
#define __ImageBase
Definition: crt_handler.c:22
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define GetProcAddress(x, y)
Definition: compat.h:753
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define CALLBACK
Definition: compat.h:35
#define MultiByteToWideChar
Definition: compat.h:110
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
BOOL WINAPI EnumResourceNamesW(HMODULE hmod, LPCWSTR type, ENUMRESNAMEPROCW lpfun, LONG_PTR lparam)
Definition: res.c:358
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
const WCHAR * str
#define CP_UTF8
Definition: nls.h:20
HRESULT __wine_unregister_resources(HMODULE module)
Definition: register.c:124
HRESULT __cdecl __wine_register_resources_new(void)
Definition: register.c:138
static const WCHAR atl100W[]
Definition: register.c:44
static HMODULE atl100
Definition: register.c:56
static void * image_base(void)
Definition: register.c:33
static IRegistrar * create_registrar(HMODULE inst, struct reg_info *info)
Definition: register.c:59
static const WCHAR moduleW[]
Definition: register.c:46
HRESULT __cdecl __wine_unregister_resources_new(void)
Definition: register.c:150
static BOOL CALLBACK register_resource(HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg)
Definition: register.c:84
HRESULT __wine_register_resources(HMODULE module)
Definition: register.c:112
static const WCHAR systemrootW[]
Definition: register.c:47
static const WCHAR regtypeW[]
Definition: register.c:45
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
Definition: name.c:39
BOOL do_register
Definition: register.c:52
HRESULT result
Definition: register.c:53
IRegistrar * registrar
Definition: register.c:51
#define HRESULT
Definition: msvc.h:7
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184