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
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};
39 IRegistrar
*registrar
;
44 static HMODULE atl100
;
45 static HRESULT (WINAPI
*pAtlCreateRegistrar
)(IRegistrar
**);
47 static IRegistrar
*create_registrar( HMODULE inst
, struct reg_info
*info
)
49 if (!pAtlCreateRegistrar
)
51 if (!(atl100
= LoadLibraryW( atl100W
)) ||
52 !(pAtlCreateRegistrar
= (void *)GetProcAddress( atl100
, "AtlCreateRegistrar" )))
54 info
->result
= E_NOINTERFACE
;
59 info
->result
= pAtlCreateRegistrar( &info
->registrar
);
60 if (SUCCEEDED( info
->result
))
64 GetModuleFileNameW( inst
, str
, MAX_PATH
);
65 IRegistrar_AddReplacement( info
->registrar
, moduleW
, str
);
67 return info
->registrar
;
70 static BOOL CALLBACK
register_resource( HMODULE module
, LPCWSTR type
, LPWSTR name
, LONG_PTR arg
)
72 struct reg_info
*info
= (struct reg_info
*)arg
;
74 HRSRC rsrc
= FindResourceW( module
, name
, type
);
75 char *str
= LoadResource( module
, rsrc
);
76 DWORD lenW
, lenA
= SizeofResource( module
, rsrc
);
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
) )))
83 info
->result
= E_OUTOFMEMORY
;
86 MultiByteToWideChar( CP_UTF8
, 0, str
, lenA
, buffer
, lenW
);
89 if (info
->do_register
)
90 info
->result
= IRegistrar_StringRegister( info
->registrar
, buffer
);
92 info
->result
= IRegistrar_StringUnregister( info
->registrar
, buffer
);
94 HeapFree( GetProcessHeap(), 0, buffer
);
95 return SUCCEEDED(info
->result
);
98 HRESULT
__wine_register_resources( HMODULE module
)
100 struct reg_info info
;
102 info
.registrar
= NULL
;
103 info
.do_register
= TRUE
;
105 EnumResourceNamesW( module
, regtypeW
, register_resource
, (LONG_PTR
)&info
);
106 if (info
.registrar
) IRegistrar_Release( info
.registrar
);
110 HRESULT
__wine_unregister_resources( HMODULE module
)
112 struct reg_info info
;
114 info
.registrar
= NULL
;
115 info
.do_register
= FALSE
;
117 EnumResourceNamesW( module
, regtypeW
, register_resource
, (LONG_PTR
)&info
);
118 if (info
.registrar
) IRegistrar_Release( info
.registrar
);