ReactOS  0.4.12-dev-685-gf36cbf7
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 
33 static const WCHAR atl100W[] = {'a','t','l','1','0','0','.','d','l','l',0};
34 static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
35 static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
36 
37 struct reg_info
38 {
42 };
43 
44 static HMODULE atl100;
45 static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
46 
48 {
49  if (!pAtlCreateRegistrar)
50  {
51  if (!(atl100 = LoadLibraryW( atl100W )) ||
52  !(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
53  {
54  info->result = E_NOINTERFACE;
55  return NULL;
56  }
57  }
58 
59  info->result = pAtlCreateRegistrar( &info->registrar );
60  if (SUCCEEDED( info->result ))
61  {
63 
65  IRegistrar_AddReplacement( info->registrar, moduleW, str );
66  }
67  return info->registrar;
68 }
69 
71 {
72  struct reg_info *info = (struct reg_info *)arg;
73  WCHAR *buffer;
74  HRSRC rsrc = FindResourceW( module, name, type );
75  char *str = LoadResource( module, rsrc );
76  DWORD lenW, lenA = SizeofResource( module, rsrc );
77 
78  if (!str) return FALSE;
79  if (!info->registrar && !create_registrar( module, info )) return FALSE;
80  lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
81  if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
82  {
83  info->result = E_OUTOFMEMORY;
84  return FALSE;
85  }
86  MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
87  buffer[lenW - 1] = 0;
88 
89  if (info->do_register)
90  info->result = IRegistrar_StringRegister( info->registrar, buffer );
91  else
92  info->result = IRegistrar_StringUnregister( info->registrar, buffer );
93 
95  return SUCCEEDED(info->result);
96 }
97 
99 {
100  struct reg_info info;
101 
102  info.registrar = NULL;
103  info.do_register = TRUE;
104  info.result = S_OK;
106  if (info.registrar) IRegistrar_Release( info.registrar );
107  return info.result;
108 }
109 
111 {
112  struct reg_info info;
113 
114  info.registrar = NULL;
115  info.do_register = FALSE;
116  info.result = S_OK;
118  if (info.registrar) IRegistrar_Release( info.registrar );
119  return info.result;
120 }
static HRESULT(WINAPI *pAtlCreateRegistrar)(IRegistrar **)
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define TRUE
Definition: types.h:120
#define E_NOINTERFACE
Definition: winerror.h:2364
static BOOL CALLBACK register_resource(HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg)
Definition: register.c:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CALLBACK
Definition: compat.h:27
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint buffer
Definition: glext.h:5915
IRegistrar * registrar
Definition: register.c:39
HRSRC WINAPI FindResourceW(HINSTANCE hModule, LPCWSTR name, LPCWSTR type)
Definition: res.c:176
BOOL do_register
Definition: register.c:40
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define CP_UTF8
Definition: nls.h:20
HGLOBAL WINAPI LoadResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:532
const WCHAR * str
static IRegistrar * create_registrar(HMODULE inst, struct reg_info *info)
Definition: register.c:47
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
HRESULT __wine_unregister_resources(HMODULE module)
Definition: register.c:110
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG HRESULT
Definition: typedefs.h:77
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR regtypeW[]
Definition: register.c:34
BOOL WINAPI EnumResourceNamesW(HMODULE hmod, LPCWSTR type, ENUMRESNAMEPROCW lpfun, LONG_PTR lparam)
Definition: res.c:358
static const WCHAR atl100W[]
Definition: register.c:33
static HMODULE atl100
Definition: register.c:44
HRESULT result
Definition: register.c:41
#define WINAPI
Definition: msvc.h:20
#define S_OK
Definition: intsafe.h:59
HRESULT __wine_register_resources(HMODULE module)
Definition: register.c:98
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DWORD WINAPI SizeofResource(HINSTANCE hModule, HRSRC hRsrc)
Definition: res.c:568
#define MultiByteToWideChar
Definition: compat.h:100
static const WCHAR moduleW[]
Definition: register.c:35
Definition: name.c:36
#define GetProcAddress(x, y)
Definition: compat.h:410
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
#define SUCCEEDED(hr)
Definition: intsafe.h:57