ddraw: Use unsafe_impl_from_IDirect3DViewport for application provided interfaces.
[wine/multimedia.git] / dlls / winecrt0 / register.c
blob407dfbdfa13d305c1cdd67e565ab4da84589e96a
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 "config.h"
22 #include <stdarg.h>
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"
33 static const WCHAR ole32W[] = {'o','l','e','3','2','.','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};
37 struct reg_info
39 IRegistrar *registrar;
40 BOOL do_register;
41 BOOL uninit;
42 HRESULT result;
45 static HMODULE ole32;
46 static HRESULT (WINAPI *pCoInitialize)(LPVOID);
47 static void (WINAPI *pCoUninitialize)(void);
48 static HRESULT (WINAPI *pCoCreateInstance)(REFCLSID,LPUNKNOWN,DWORD,REFIID,LPVOID*);
50 static IRegistrar *create_registrar( HMODULE inst, struct reg_info *info )
52 if (!pCoCreateInstance)
54 if (!(ole32 = LoadLibraryW( ole32W )) ||
55 !(pCoInitialize = (void *)GetProcAddress( ole32, "CoInitialize" )) ||
56 !(pCoUninitialize = (void *)GetProcAddress( ole32, "CoUninitialize" )) ||
57 !(pCoCreateInstance = (void *)GetProcAddress( ole32, "CoCreateInstance" )))
59 info->result = E_NOINTERFACE;
60 return NULL;
63 info->uninit = SUCCEEDED( pCoInitialize( NULL ));
65 info->result = pCoCreateInstance( &CLSID_Registrar, NULL, CLSCTX_INPROC_SERVER,
66 &IID_IRegistrar, (void **)&info->registrar );
67 if (SUCCEEDED( info->result ))
69 WCHAR str[MAX_PATH];
71 GetModuleFileNameW( inst, str, MAX_PATH );
72 IRegistrar_AddReplacement( info->registrar, moduleW, str );
74 return info->registrar;
77 static BOOL CALLBACK register_resource( HMODULE module, LPCWSTR type, LPWSTR name, LONG_PTR arg )
79 struct reg_info *info = (struct reg_info *)arg;
80 WCHAR *buffer;
81 HRSRC rsrc = FindResourceW( module, name, type );
82 char *str = LoadResource( module, rsrc );
83 DWORD lenW, lenA = SizeofResource( module, rsrc );
85 if (!str) return FALSE;
86 if (!info->registrar && !create_registrar( module, info )) return FALSE;
87 lenW = MultiByteToWideChar( CP_UTF8, 0, str, lenA, NULL, 0 ) + 1;
88 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, lenW * sizeof(WCHAR) )))
90 info->result = E_OUTOFMEMORY;
91 return FALSE;
93 MultiByteToWideChar( CP_UTF8, 0, str, lenA, buffer, lenW );
94 buffer[lenW - 1] = 0;
96 if (info->do_register)
97 info->result = IRegistrar_StringRegister( info->registrar, buffer );
98 else
99 info->result = IRegistrar_StringUnregister( info->registrar, buffer );
101 HeapFree( GetProcessHeap(), 0, buffer );
102 return SUCCEEDED(info->result);
105 HRESULT __wine_register_resources( HMODULE module )
107 struct reg_info info;
109 info.registrar = NULL;
110 info.do_register = TRUE;
111 info.uninit = FALSE;
112 info.result = S_OK;
113 EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
114 if (info.registrar) IRegistrar_Release( info.registrar );
115 if (info.uninit) pCoUninitialize();
116 return info.result;
119 HRESULT __wine_unregister_resources( HMODULE module )
121 struct reg_info info;
123 info.registrar = NULL;
124 info.do_register = FALSE;
125 info.uninit = FALSE;
126 info.result = S_OK;
127 EnumResourceNamesW( module, regtypeW, register_resource, (LONG_PTR)&info );
128 if (info.registrar) IRegistrar_Release( info.registrar );
129 if (info.uninit) pCoUninitialize();
130 return info.result;