Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/winecrt0/register.c
12343 views
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 <stdarg.h>
22
23
#define COBJMACROS
24
#define ATL_INITGUID
25
#include "windef.h"
26
#include "winbase.h"
27
#include "winnls.h"
28
#include "ole2.h"
29
#include "rpcproxy.h"
30
#include "atliface.h"
31
32
static inline void *image_base(void)
33
{
34
#ifdef __WINE_PE_BUILD
35
extern IMAGE_DOS_HEADER __ImageBase;
36
return (void *)&__ImageBase;
37
#else
38
extern IMAGE_NT_HEADERS __wine_spec_nt_header;
39
return (void *)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
40
#endif
41
}
42
43
static const WCHAR atl100W[] = {'a','t','l','1','0','0','.','d','l','l',0};
44
static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
45
static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
46
static const WCHAR systemrootW[] = {'S','y','s','t','e','m','R','o','o','t',0};
47
48
struct reg_info
49
{
50
IRegistrar *registrar;
51
BOOL do_register;
52
HRESULT result;
53
};
54
55
static HMODULE atl100;
56
static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
57
58
static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
59
{
60
if (!pAtlCreateRegistrar)
61
{
62
if (!(atl100 = LoadLibraryW( atl100W )) ||
63
!(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
64
{
65
info->result = E_NOINTERFACE;
66
return NULL;
67
}
68
}
69
70
info->result = pAtlCreateRegistrar( &info->registrar );
71
if (SUCCEEDED( info->result ))
72
{
73
WCHAR str[MAX_PATH];
74
75
GetModuleFileNameW( inst, str, MAX_PATH );
76
IRegistrar_AddReplacement( info->registrar, moduleW, str );
77
GetEnvironmentVariableW( systemrootW, str, MAX_PATH );
78
IRegistrar_AddReplacement( info->registrar, systemrootW, str );
79
}
80
return info->registrar;
81
}
82
83
static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg )
84
{
85
struct reg_info *info = (struct reg_info *)arg;
86
WCHAR *buffer;
87
HRSRC rsrc = FindResourceW( module, name, type );
88
char *str = LoadResource( module, rsrc );
89
DWORD lenW, lenA = SizeofResource( module, rsrc );
90
91
if (!str) return FALSE;
92
if (!info->registrar && !create_registrar( module, info )) return FALSE;
93
lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
94
if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
95
{
96
info->result = E_OUTOFMEMORY;
97
return FALSE;
98
}
99
MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
100
buffer[lenW - 1] = 0;
101
102
if (info->do_register)
103
info->result = IRegistrar_StringRegister( info->registrar, buffer );
104
else
105
info->result = IRegistrar_StringUnregister( info->registrar, buffer );
106
107
HeapFree( GetProcessHeap(), 0, buffer );
108
return SUCCEEDED(info->result);
109
}
110
111
HRESULT __cdecl __wine_register_resources(void)
112
{
113
struct reg_info info;
114
115
info.registrar = NULL;
116
info.do_register = TRUE;
117
info.result = S_OK;
118
EnumResourceNamesW( image_base(), regtypeW, register_resource, (LONG_PTR)&info );
119
if (info.registrar) IRegistrar_Release( info.registrar );
120
return info.result;
121
}
122
123
HRESULT __cdecl __wine_unregister_resources(void)
124
{
125
struct reg_info info;
126
127
info.registrar = NULL;
128
info.do_register = FALSE;
129
info.result = S_OK;
130
EnumResourceNamesW( image_base(), regtypeW, register_resource, (LONG_PTR)&info );
131
if (info.registrar) IRegistrar_Release( info.registrar );
132
return info.result;
133
}
134
135