dinput: Clear DIA_APPNOMAP BuildActionMap flag with specific device semantic.
[wine.git] / dlls / winecrt0 / register.c
blob757e424fed50c1153f0ccfa4a9b0c3d4f385e9d3
1 /*
2 * Support functions for Wine dll registrations
4 * Copyright (c) 2010 Alexandre Julliard
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.
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.
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
21 #include <stdarg.h>
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"
32 static inline void *image_base(void)
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
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};
48 struct reg_info
50 IRegistrar *registrar;
51 BOOL do_register;
52 HRESULT result;
55 static HMODULE atl100;
56 static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
58 static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
60 if (!pAtlCreateRegistrar)
62 if (!(atl100 = LoadLibraryW( atl100W )) ||
63 !(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
65 info->result = E_NOINTERFACE;
66 return NULL;
70 info->result = pAtlCreateRegistrar( &info->registrar );
71 if (SUCCEEDED( info->result ))
73 WCHAR str[MAX_PATH];
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 );
80 return info->registrar;
83 static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg )
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 );
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) )))
96 info->result = E_OUTOFMEMORY;
97 return FALSE;
99 MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
100 buffer[lenW - 1] = 0;
102 if (info->do_register)
103 info->result = IRegistrar_StringRegister( info->registrar, buffer );
104 else
105 info->result = IRegistrar_StringUnregister( info->registrar, buffer );
107 HeapFree( GetProcessHeap(), 0, buffer );
108 return SUCCEEDED(info->result);
111 HRESULT __cdecl __wine_register_resources(void)
113 struct reg_info info;
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;
123 HRESULT __cdecl __wine_unregister_resources(void)
125 struct reg_info info;
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;