dinput: Factor out IDirectInputDevice ansi vtable.
[wine.git] / dlls / atl / registrar.c
blob7c3c5976b228337a6b0ba3ac5a3a21e401cb2333
1 /*
2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include "atlbase.h"
23 #include "wine/debug.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(atl);
27 /**************************************************************
28 * ATLRegistrar implementation
31 static const struct {
32 WCHAR name[22];
33 HKEY key;
34 } root_keys[] = {
35 {L"HKEY_CLASSES_ROOT", HKEY_CLASSES_ROOT},
36 {L"HKEY_CURRENT_USER", HKEY_CURRENT_USER},
37 {L"HKEY_LOCAL_MACHINE", HKEY_LOCAL_MACHINE},
38 {L"HKEY_USERS", HKEY_USERS},
39 {L"HKEY_PERFORMANCE_DATA", HKEY_PERFORMANCE_DATA},
40 {L"HKEY_DYN_DATA", HKEY_DYN_DATA},
41 {L"HKEY_CURRENT_CONFIG", HKEY_CURRENT_CONFIG},
42 {L"HKCR", HKEY_CLASSES_ROOT},
43 {L"HKCU", HKEY_CURRENT_USER},
44 {L"HKLM", HKEY_LOCAL_MACHINE},
45 {L"HKU", HKEY_USERS},
46 {L"HKPD", HKEY_PERFORMANCE_DATA},
47 {L"HKDD", HKEY_DYN_DATA},
48 {L"HKCC", HKEY_CURRENT_CONFIG}
51 typedef struct rep_list_str {
52 LPOLESTR key;
53 LPOLESTR item;
54 int key_len;
55 struct rep_list_str *next;
56 } rep_list;
58 typedef struct {
59 IRegistrar IRegistrar_iface;
60 LONG ref;
61 rep_list *rep;
62 } Registrar;
64 typedef struct {
65 LPOLESTR str;
66 DWORD alloc;
67 DWORD len;
68 } strbuf;
70 static inline Registrar *impl_from_IRegistrar(IRegistrar *iface)
72 return CONTAINING_RECORD(iface, Registrar, IRegistrar_iface);
75 static void strbuf_init(strbuf *buf)
77 buf->str = HeapAlloc(GetProcessHeap(), 0, 128*sizeof(WCHAR));
78 buf->alloc = 128;
79 buf->len = 0;
82 static void strbuf_write(LPCOLESTR str, strbuf *buf, int len)
84 if(len == -1)
85 len = lstrlenW(str);
86 if(buf->len+len+1 >= buf->alloc) {
87 buf->alloc = (buf->len+len)<<1;
88 buf->str = HeapReAlloc(GetProcessHeap(), 0, buf->str, buf->alloc*sizeof(WCHAR));
90 memcpy(buf->str+buf->len, str, len*sizeof(OLECHAR));
91 buf->len += len;
92 buf->str[buf->len] = '\0';
95 static int xdigit_to_int(WCHAR c)
97 if('0' <= c && c <= '9') return c - '0';
98 if('a' <= c && c <= 'f') return c - 'a' + 10;
99 if('A' <= c && c <= 'F') return c - 'A' + 10;
100 return -1;
103 static HRESULT get_word(LPCOLESTR *str, strbuf *buf)
105 LPCOLESTR iter, iter2 = *str;
107 buf->len = 0;
108 buf->str[0] = '\0';
110 while(iswspace(*iter2))
111 iter2++;
112 iter = iter2;
113 if(!*iter) {
114 *str = iter;
115 return S_OK;
118 if(*iter == '}' || *iter == '=') {
119 strbuf_write(iter++, buf, 1);
120 }else if(*iter == '\'') {
121 iter2 = ++iter;
122 iter = wcschr(iter, '\'');
123 if(!iter) {
124 WARN("Unexpected end of script\n");
125 *str = iter;
126 return DISP_E_EXCEPTION;
128 strbuf_write(iter2, buf, iter-iter2);
129 iter++;
130 }else {
131 while(*iter && !iswspace(*iter))
132 iter++;
133 strbuf_write(iter2, buf, iter-iter2);
136 while(iswspace(*iter))
137 iter++;
138 *str = iter;
139 return S_OK;
142 static HRESULT do_preprocess(const Registrar *This, LPCOLESTR data, strbuf *buf)
144 LPCOLESTR iter, iter2 = data;
145 rep_list *rep_iter;
147 iter = wcschr(data, '%');
148 while(iter) {
149 strbuf_write(iter2, buf, iter-iter2);
151 iter2 = ++iter;
152 if(!*iter2)
153 return DISP_E_EXCEPTION;
154 iter = wcschr(iter2, '%');
155 if(!iter)
156 return DISP_E_EXCEPTION;
158 if(iter == iter2) {
159 strbuf_write(L"%", buf, 1);
160 }else {
161 for(rep_iter = This->rep; rep_iter; rep_iter = rep_iter->next) {
162 if(rep_iter->key_len == iter-iter2
163 && !wcsnicmp(iter2, rep_iter->key, rep_iter->key_len))
164 break;
166 if(!rep_iter) {
167 WARN("Could not find replacement: %s\n", debugstr_wn(iter2, iter-iter2));
168 return DISP_E_EXCEPTION;
171 strbuf_write(rep_iter->item, buf, -1);
174 iter2 = ++iter;
175 iter = wcschr(iter, '%');
178 strbuf_write(iter2, buf, -1);
179 TRACE("%s\n", debugstr_w(buf->str));
181 return S_OK;
184 static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOOL do_register)
186 LPCOLESTR iter;
187 HRESULT hres;
188 LONG lres;
189 HKEY hkey = 0;
190 strbuf name;
192 enum {
193 NORMAL,
194 NO_REMOVE,
195 IS_VAL,
196 FORCE_REMOVE,
197 DO_DELETE
198 } key_type = NORMAL;
200 iter = *pstr;
201 hres = get_word(&iter, buf);
202 if(FAILED(hres))
203 return hres;
204 strbuf_init(&name);
206 while(buf->str[1] || buf->str[0] != '}') {
207 key_type = NORMAL;
208 if(!lstrcmpiW(buf->str, L"NoRemove"))
209 key_type = NO_REMOVE;
210 else if(!lstrcmpiW(buf->str, L"ForceRemove"))
211 key_type = FORCE_REMOVE;
212 else if(!lstrcmpiW(buf->str, L"val"))
213 key_type = IS_VAL;
214 else if(!lstrcmpiW(buf->str, L"Delete"))
215 key_type = DO_DELETE;
217 if(key_type != NORMAL) {
218 hres = get_word(&iter, buf);
219 if(FAILED(hres))
220 break;
222 TRACE("name = %s\n", debugstr_w(buf->str));
224 if(do_register) {
225 if(key_type == IS_VAL) {
226 hkey = parent_key;
227 strbuf_write(buf->str, &name, -1);
228 }else if(key_type == DO_DELETE) {
229 TRACE("Deleting %s\n", debugstr_w(buf->str));
230 RegDeleteTreeW(parent_key, buf->str);
231 }else {
232 if(key_type == FORCE_REMOVE)
233 RegDeleteTreeW(parent_key, buf->str);
234 lres = RegCreateKeyW(parent_key, buf->str, &hkey);
235 if(lres != ERROR_SUCCESS) {
236 WARN("Could not create(open) key: %08x\n", lres);
237 hres = HRESULT_FROM_WIN32(lres);
238 break;
241 }else if(key_type != IS_VAL && key_type != DO_DELETE) {
242 strbuf_write(buf->str, &name, -1);
243 lres = RegOpenKeyW(parent_key, buf->str, &hkey);
244 if(lres != ERROR_SUCCESS)
245 WARN("Could not open key %s: %08x\n", debugstr_w(name.str), lres);
248 if(key_type != DO_DELETE && *iter == '=') {
249 iter++;
250 hres = get_word(&iter, buf);
251 if(FAILED(hres))
252 break;
253 if(buf->len != 1) {
254 WARN("Wrong registry type: %s\n", debugstr_w(buf->str));
255 hres = DISP_E_EXCEPTION;
256 break;
258 if(do_register) {
259 switch(buf->str[0]) {
260 case 's':
261 hres = get_word(&iter, buf);
262 if(FAILED(hres))
263 break;
264 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_SZ, (PBYTE)buf->str,
265 (lstrlenW(buf->str)+1)*sizeof(WCHAR));
266 if(lres != ERROR_SUCCESS) {
267 WARN("Could set value of key: %08x\n", lres);
268 hres = HRESULT_FROM_WIN32(lres);
269 break;
271 break;
272 case 'd': {
273 DWORD dw;
274 hres = get_word(&iter, buf);
275 if(FAILED(hres))
276 break;
277 dw = wcstol(buf->str, NULL, 10);
278 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_DWORD,
279 (PBYTE)&dw, sizeof(dw));
280 if(lres != ERROR_SUCCESS) {
281 WARN("Could set value of key: %08x\n", lres);
282 hres = HRESULT_FROM_WIN32(lres);
283 break;
285 break;
287 case 'b': {
288 BYTE *bytes;
289 DWORD count;
290 DWORD i;
291 hres = get_word(&iter, buf);
292 if(FAILED(hres))
293 break;
294 count = (lstrlenW(buf->str) + 1) / 2;
295 bytes = HeapAlloc(GetProcessHeap(), 0, count);
296 if(bytes == NULL) {
297 hres = E_OUTOFMEMORY;
298 break;
300 for(i = 0; i < count && buf->str[2*i]; i++) {
301 int d1, d2;
302 if((d1 = xdigit_to_int(buf->str[2*i])) == -1 || (d2 = xdigit_to_int(buf->str[2*i + 1])) == -1) {
303 hres = E_FAIL;
304 break;
306 bytes[i] = (d1 << 4) | d2;
308 if(SUCCEEDED(hres)) {
309 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY,
310 bytes, count);
311 if(lres != ERROR_SUCCESS) {
312 WARN("Could not set value of key: 0x%08x\n", lres);
313 hres = HRESULT_FROM_WIN32(lres);
316 HeapFree(GetProcessHeap(), 0, bytes);
317 break;
319 default:
320 WARN("Wrong resource type: %s\n", debugstr_w(buf->str));
321 hres = DISP_E_EXCEPTION;
323 if(FAILED(hres))
324 break;
325 }else {
326 if(*iter == '-')
327 iter++;
328 hres = get_word(&iter, buf);
329 if(FAILED(hres))
330 break;
332 }else if(key_type == IS_VAL) {
333 WARN("value not set!\n");
334 hres = DISP_E_EXCEPTION;
335 break;
338 if(key_type != IS_VAL && key_type != DO_DELETE && *iter == '{' && iswspace(iter[1])) {
339 hres = get_word(&iter, buf);
340 if(FAILED(hres))
341 break;
342 hres = do_process_key(&iter, hkey, buf, do_register);
343 if(FAILED(hres))
344 break;
347 TRACE("%x %x\n", do_register, key_type);
348 if(!do_register && (key_type == NORMAL || key_type == FORCE_REMOVE)) {
349 TRACE("Deleting %s\n", debugstr_w(name.str));
350 RegDeleteKeyW(parent_key, name.str);
353 if(hkey && key_type != IS_VAL)
354 RegCloseKey(hkey);
355 hkey = 0;
356 name.len = 0;
358 hres = get_word(&iter, buf);
359 if(FAILED(hres))
360 break;
363 HeapFree(GetProcessHeap(), 0, name.str);
364 if(hkey && key_type != IS_VAL)
365 RegCloseKey(hkey);
366 *pstr = iter;
367 return hres;
370 static HRESULT do_process_root_key(LPCOLESTR data, BOOL do_register)
372 LPCOLESTR iter = data;
373 strbuf buf;
374 HRESULT hres;
375 unsigned int i;
377 strbuf_init(&buf);
378 hres = get_word(&iter, &buf);
379 if(FAILED(hres))
380 return hres;
382 while(*iter) {
383 if(!buf.len) {
384 WARN("ward.len == 0, failed\n");
385 hres = DISP_E_EXCEPTION;
386 break;
388 for(i=0; i<ARRAY_SIZE(root_keys); i++) {
389 if(!lstrcmpiW(buf.str, root_keys[i].name))
390 break;
392 if(i == ARRAY_SIZE(root_keys)) {
393 WARN("Wrong root key name: %s\n", debugstr_w(buf.str));
394 hres = DISP_E_EXCEPTION;
395 break;
397 hres = get_word(&iter, &buf);
398 if(FAILED(hres))
399 break;
400 if(buf.str[1] || buf.str[0] != '{') {
401 WARN("Failed, expected '{', got %s\n", debugstr_w(buf.str));
402 hres = DISP_E_EXCEPTION;
403 break;
405 hres = do_process_key(&iter, root_keys[i].key, &buf, do_register);
406 if(FAILED(hres)) {
407 WARN("Processing key failed: %08x\n", hres);
408 break;
410 hres = get_word(&iter, &buf);
411 if(FAILED(hres))
412 break;
414 HeapFree(GetProcessHeap(), 0, buf.str);
415 return hres;
418 static HRESULT string_register(Registrar *This, LPCOLESTR data, BOOL do_register)
420 strbuf buf;
421 HRESULT hres;
423 TRACE("(%p %s %x)\n", This, debugstr_w(data), do_register);
425 strbuf_init(&buf);
426 hres = do_preprocess(This, data, &buf);
427 if(FAILED(hres)) {
428 WARN("preprocessing failed!\n");
429 HeapFree(GetProcessHeap(), 0, buf.str);
430 return hres;
433 hres = do_process_root_key(buf.str, do_register);
434 if(FAILED(hres) && do_register)
435 do_process_root_key(buf.str, FALSE);
437 HeapFree(GetProcessHeap(), 0, buf.str);
438 return hres;
441 static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName,
442 LPCOLESTR szID, LPCOLESTR szType, BOOL do_register)
444 HINSTANCE hins;
445 HRSRC src;
446 LPSTR regstra;
447 LPWSTR regstrw;
448 DWORD len, reslen;
449 HRESULT hres;
451 hins = LoadLibraryExW(resFileName, NULL, LOAD_LIBRARY_AS_DATAFILE);
452 if(hins) {
453 src = FindResourceW(hins, szID, szType);
454 if(src) {
455 regstra = LoadResource(hins, src);
456 reslen = SizeofResource(hins, src);
457 if(regstra) {
458 len = MultiByteToWideChar(CP_ACP, 0, regstra, reslen, NULL, 0)+1;
459 regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
460 MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, len);
461 regstrw[len-1] = '\0';
463 hres = string_register(This, regstrw, do_register);
465 HeapFree(GetProcessHeap(), 0, regstrw);
466 }else {
467 WARN("could not load resource\n");
468 hres = HRESULT_FROM_WIN32(GetLastError());
470 }else {
471 WARN("Could not find source\n");
472 hres = HRESULT_FROM_WIN32(GetLastError());
474 FreeLibrary(hins);
475 }else {
476 WARN("Could not load resource file\n");
477 hres = HRESULT_FROM_WIN32(GetLastError());
480 return hres;
483 static HRESULT file_register(Registrar *This, LPCOLESTR fileName, BOOL do_register)
485 HANDLE file;
486 DWORD filelen, len;
487 LPWSTR regstrw;
488 LPSTR regstra;
489 HRESULT hres;
491 file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
492 if(file != INVALID_HANDLE_VALUE) {
493 filelen = GetFileSize(file, NULL);
494 regstra = HeapAlloc(GetProcessHeap(), 0, filelen);
495 if(ReadFile(file, regstra, filelen, NULL, NULL)) {
496 len = MultiByteToWideChar(CP_ACP, 0, regstra, filelen, NULL, 0)+1;
497 regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
498 MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, len);
499 regstrw[len-1] = '\0';
501 hres = string_register(This, regstrw, do_register);
503 HeapFree(GetProcessHeap(), 0, regstrw);
504 }else {
505 WARN("Failed to read file %s\n", debugstr_w(fileName));
506 hres = HRESULT_FROM_WIN32(GetLastError());
508 HeapFree(GetProcessHeap(), 0, regstra);
509 CloseHandle(file);
510 }else {
511 WARN("Could not open file %s\n", debugstr_w(fileName));
512 hres = HRESULT_FROM_WIN32(GetLastError());
515 return hres;
518 static HRESULT WINAPI Registrar_QueryInterface(IRegistrar *iface, REFIID riid, void **ppvObject)
520 TRACE("(%p)->(%s %p\n", iface, debugstr_guid(riid), ppvObject);
522 if(IsEqualGUID(&IID_IUnknown, riid)
523 || IsEqualGUID(&IID_IRegistrar, riid)
524 || IsEqualGUID(&IID_IRegistrarBase, riid)) {
525 IRegistrar_AddRef(iface);
526 *ppvObject = iface;
527 return S_OK;
529 return E_NOINTERFACE;
532 static ULONG WINAPI Registrar_AddRef(IRegistrar *iface)
534 Registrar *This = impl_from_IRegistrar(iface);
535 ULONG ref = InterlockedIncrement(&This->ref);
536 TRACE("(%p) ->%d\n", This, ref);
537 return ref;
540 static ULONG WINAPI Registrar_Release(IRegistrar *iface)
542 Registrar *This = impl_from_IRegistrar(iface);
543 ULONG ref = InterlockedDecrement(&This->ref);
545 TRACE("(%p) ->%d\n", This, ref);
546 if(!ref) {
547 IRegistrar_ClearReplacements(iface);
548 HeapFree(GetProcessHeap(), 0, This);
550 return ref;
553 static HRESULT WINAPI Registrar_AddReplacement(IRegistrar *iface, LPCOLESTR Key, LPCOLESTR item)
555 Registrar *This = impl_from_IRegistrar(iface);
556 int len;
557 rep_list *new_rep;
559 TRACE("(%p)->(%s %s)\n", This, debugstr_w(Key), debugstr_w(item));
561 new_rep = HeapAlloc(GetProcessHeap(), 0, sizeof(rep_list));
563 new_rep->key_len = lstrlenW(Key);
564 new_rep->key = HeapAlloc(GetProcessHeap(), 0, (new_rep->key_len + 1) * sizeof(OLECHAR));
565 memcpy(new_rep->key, Key, (new_rep->key_len+1)*sizeof(OLECHAR));
567 len = lstrlenW(item)+1;
568 new_rep->item = HeapAlloc(GetProcessHeap(), 0, len*sizeof(OLECHAR));
569 memcpy(new_rep->item, item, len*sizeof(OLECHAR));
571 new_rep->next = This->rep;
572 This->rep = new_rep;
574 return S_OK;
577 static HRESULT WINAPI Registrar_ClearReplacements(IRegistrar *iface)
579 Registrar *This = impl_from_IRegistrar(iface);
580 rep_list *iter, *iter2;
582 TRACE("(%p)\n", This);
584 if(!This->rep)
585 return S_OK;
587 iter = This->rep;
588 while(iter) {
589 iter2 = iter->next;
590 HeapFree(GetProcessHeap(), 0, iter->key);
591 HeapFree(GetProcessHeap(), 0, iter->item);
592 HeapFree(GetProcessHeap(), 0, iter);
593 iter = iter2;
596 This->rep = NULL;
597 return S_OK;
600 static HRESULT WINAPI Registrar_ResourceRegisterSz(IRegistrar* iface, LPCOLESTR resFileName,
601 LPCOLESTR szID, LPCOLESTR szType)
603 Registrar *This = impl_from_IRegistrar(iface);
604 TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
605 return resource_register(This, resFileName, szID, szType, TRUE);
608 static HRESULT WINAPI Registrar_ResourceUnregisterSz(IRegistrar* iface, LPCOLESTR resFileName,
609 LPCOLESTR szID, LPCOLESTR szType)
611 Registrar *This = impl_from_IRegistrar(iface);
612 TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
613 return resource_register(This, resFileName, szID, szType, FALSE);
616 static HRESULT WINAPI Registrar_FileRegister(IRegistrar* iface, LPCOLESTR fileName)
618 Registrar *This = impl_from_IRegistrar(iface);
619 TRACE("(%p)->(%s)\n", This, debugstr_w(fileName));
620 return file_register(This, fileName, TRUE);
623 static HRESULT WINAPI Registrar_FileUnregister(IRegistrar* iface, LPCOLESTR fileName)
625 Registrar *This = impl_from_IRegistrar(iface);
626 FIXME("(%p)->(%s)\n", This, debugstr_w(fileName));
627 return file_register(This, fileName, FALSE);
630 static HRESULT WINAPI Registrar_StringRegister(IRegistrar* iface, LPCOLESTR data)
632 Registrar *This = impl_from_IRegistrar(iface);
633 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
634 return string_register(This, data, TRUE);
637 static HRESULT WINAPI Registrar_StringUnregister(IRegistrar* iface, LPCOLESTR data)
639 Registrar *This = impl_from_IRegistrar(iface);
640 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
641 return string_register(This, data, FALSE);
644 static HRESULT WINAPI Registrar_ResourceRegister(IRegistrar* iface, LPCOLESTR resFileName,
645 UINT nID, LPCOLESTR szType)
647 Registrar *This = impl_from_IRegistrar(iface);
648 TRACE("(%p)->(%s %d %s)\n", iface, debugstr_w(resFileName), nID, debugstr_w(szType));
649 return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, TRUE);
652 static HRESULT WINAPI Registrar_ResourceUnregister(IRegistrar* iface, LPCOLESTR resFileName,
653 UINT nID, LPCOLESTR szType)
655 Registrar *This = impl_from_IRegistrar(iface);
656 TRACE("(%p)->(%s %d %s)\n", This, debugstr_w(resFileName), nID, debugstr_w(szType));
657 return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, FALSE);
660 static const IRegistrarVtbl RegistrarVtbl = {
661 Registrar_QueryInterface,
662 Registrar_AddRef,
663 Registrar_Release,
664 Registrar_AddReplacement,
665 Registrar_ClearReplacements,
666 Registrar_ResourceRegisterSz,
667 Registrar_ResourceUnregisterSz,
668 Registrar_FileRegister,
669 Registrar_FileUnregister,
670 Registrar_StringRegister,
671 Registrar_StringUnregister,
672 Registrar_ResourceRegister,
673 Registrar_ResourceUnregister,
676 /***********************************************************************
677 * AtlCreateRegistrar [atl100.@]
679 HRESULT WINAPI AtlCreateRegistrar(IRegistrar **ret)
681 Registrar *registrar;
683 registrar = HeapAlloc(GetProcessHeap(), 0, sizeof(*registrar));
684 if(!registrar)
685 return E_OUTOFMEMORY;
687 registrar->IRegistrar_iface.lpVtbl = &RegistrarVtbl;
688 registrar->ref = 1;
689 registrar->rep = NULL;
691 *ret = &registrar->IRegistrar_iface;
692 return S_OK;
695 /***********************************************************************
696 * AtlUpdateRegistryFromResourceD [atl100.@]
698 HRESULT WINAPI AtlUpdateRegistryFromResourceD(HINSTANCE inst, LPCOLESTR res,
699 BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries, IRegistrar *pReg)
701 const struct _ATL_REGMAP_ENTRY *iter;
702 WCHAR module_name[MAX_PATH];
703 IRegistrar *registrar;
704 HRESULT hres;
706 if(!GetModuleFileNameW(inst, module_name, MAX_PATH)) {
707 FIXME("hinst %p: did not get module name\n", inst);
708 return E_FAIL;
711 TRACE("%p (%s), %s, %d, %p, %p\n", inst, debugstr_w(module_name),
712 debugstr_w(res), bRegister, pMapEntries, pReg);
714 if(pReg) {
715 registrar = pReg;
716 }else {
717 hres = AtlCreateRegistrar(&registrar);
718 if(FAILED(hres))
719 return hres;
722 IRegistrar_AddReplacement(registrar, L"MODULE", module_name);
724 for (iter = pMapEntries; iter && iter->szKey; iter++)
725 IRegistrar_AddReplacement(registrar, iter->szKey, iter->szData);
727 if(bRegister)
728 hres = IRegistrar_ResourceRegisterSz(registrar, module_name, res, L"REGISTRY");
729 else
730 hres = IRegistrar_ResourceUnregisterSz(registrar, module_name, res, L"REGISTRY");
732 if(registrar != pReg)
733 IRegistrar_Release(registrar);
734 return hres;