wined3d: Move swapchain buffer discarding to wined3d_cs_exec_present().
[wine.git] / dlls / winecrt0 / register.c
blobcb5e7a50f766d1e6e261e8f2f8fabd887fbef8be
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 const WCHAR atl100W[] = {'a','t','l','1','0','0','.','d','l','l',0};
33 static const WCHAR regtypeW[] = {'W','I','N','E','_','R','E','G','I','S','T','R','Y',0};
34 static const WCHAR moduleW[] = {'M','O','D','U','L','E',0};
36 struct reg_info
38 IRegistrar *registrar;
39 BOOL do_register;
40 HRESULT result;
43 static HMODULE atl100;
44 static HRESULT (WINAPI *pAtlCreateRegistrar)(IRegistrar**);
46 static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
48 if (!pAtlCreateRegistrar)
50 if (!(atl100 = LoadLibraryW( atl100W )) ||
51 !(pAtlCreateRegistrar = (void *)GetProcAddress( atl100, "AtlCreateRegistrar" )))
53 info->result = E_NOINTERFACE;
54 return NULL;
58 info->result = pAtlCreateRegistrar( &info->registrar );
59 if (SUCCEEDED( info->result ))
61 WCHAR str[MAX_PATH];
63 GetModuleFileNameW( inst, str, MAX_PATH );
64 IRegistrar_AddReplacement( info->registrar, moduleW, str );
66 return info->registrar;
69 static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg )
71 struct reg_info *info = (struct reg_info *)arg;
72 WCHAR *buffer;
73 HRSRC rsrc = FindResourceW( module, name, type );
74 char *str = LoadResource( module, rsrc );
75 DWORD lenW, lenA = SizeofResource( module, rsrc );
77 if (!str) return FALSE;
78 if (!info->registrar && !create_registrar( module, info )) return FALSE;
79 lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
80 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
82 info->result = E_OUTOFMEMORY;
83 return FALSE;
85 MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
86 buffer[lenW - 1] = 0;
88 if (info->do_register)
89 info->result = IRegistrar_StringRegister( info->registrar, buffer );
90 else
91 info->result = IRegistrar_StringUnregister( info->registrar, buffer );
93 HeapFree( GetProcessHeap(), 0, buffer );
94 return SUCCEEDED(info->result);
97 HRESULT __cdecl __wine_register_resources( HMODULE module )
99 struct reg_info info;
101 info.registrar = NULL;
102 info.do_register = TRUE;
103 info.result = S_OK;
104 EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
105 if (info.registrar) IRegistrar_Release( info.registrar );
106 return info.result;
109 HRESULT __cdecl __wine_unregister_resources( HMODULE module )
111 struct reg_info info;
113 info.registrar = NULL;
114 info.do_register = FALSE;
115 info.result = S_OK;
116 EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
117 if (info.registrar) IRegistrar_Release( info.registrar );
118 return info.result;