uiautomationcore: Initialize VARIANT in test_uia_prov_from_acc_properties() (Coverity).
[wine.git] / dlls / atl / registrar.c
blob5e03b42132c77d481802874ffa86cf071a46104a
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 = malloc(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 = realloc(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 for (;;)
123 iter2 = ++iter;
124 iter = wcschr(iter, '\'');
125 if(!iter) {
126 WARN("Unexpected end of script\n");
127 *str = iter;
128 return DISP_E_EXCEPTION;
130 if (iter[1] != '\'') break;
131 iter++;
132 strbuf_write(iter2, buf, iter-iter2);
134 strbuf_write(iter2, buf, iter-iter2);
135 iter++;
136 }else {
137 while(*iter && !iswspace(*iter))
138 iter++;
139 strbuf_write(iter2, buf, iter-iter2);
142 while(iswspace(*iter))
143 iter++;
144 *str = iter;
145 return S_OK;
148 static HRESULT do_preprocess(const Registrar *This, LPCOLESTR data, strbuf *buf)
150 LPCOLESTR iter, iter2 = data;
151 rep_list *rep_iter;
153 iter = wcschr(data, '%');
154 while(iter) {
155 strbuf_write(iter2, buf, iter-iter2);
157 iter2 = ++iter;
158 if(!*iter2)
159 return DISP_E_EXCEPTION;
160 iter = wcschr(iter2, '%');
161 if(!iter)
162 return DISP_E_EXCEPTION;
164 if(iter == iter2) {
165 strbuf_write(L"%", buf, 1);
166 }else {
167 for(rep_iter = This->rep; rep_iter; rep_iter = rep_iter->next) {
168 if(rep_iter->key_len == iter-iter2
169 && !wcsnicmp(iter2, rep_iter->key, rep_iter->key_len))
170 break;
172 if(!rep_iter) {
173 WARN("Could not find replacement: %s\n", debugstr_wn(iter2, iter-iter2));
174 return DISP_E_EXCEPTION;
177 strbuf_write(rep_iter->item, buf, -1);
180 iter2 = ++iter;
181 iter = wcschr(iter, '%');
184 strbuf_write(iter2, buf, -1);
185 TRACE("%s\n", debugstr_w(buf->str));
187 return S_OK;
190 static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOOL do_register)
192 LPCOLESTR iter;
193 HRESULT hres;
194 LONG lres;
195 HKEY hkey = 0;
196 strbuf name;
198 enum {
199 NORMAL,
200 NO_REMOVE,
201 IS_VAL,
202 FORCE_REMOVE,
203 DO_DELETE
204 } key_type = NORMAL;
206 iter = *pstr;
207 hres = get_word(&iter, buf);
208 if(FAILED(hres))
209 return hres;
210 strbuf_init(&name);
212 while(buf->str[1] || buf->str[0] != '}') {
213 key_type = NORMAL;
214 if(!lstrcmpiW(buf->str, L"NoRemove"))
215 key_type = NO_REMOVE;
216 else if(!lstrcmpiW(buf->str, L"ForceRemove"))
217 key_type = FORCE_REMOVE;
218 else if(!lstrcmpiW(buf->str, L"val"))
219 key_type = IS_VAL;
220 else if(!lstrcmpiW(buf->str, L"Delete"))
221 key_type = DO_DELETE;
223 if(key_type != NORMAL) {
224 hres = get_word(&iter, buf);
225 if(FAILED(hres))
226 break;
228 TRACE("name = %s\n", debugstr_w(buf->str));
230 if(do_register) {
231 if(key_type == IS_VAL) {
232 hkey = parent_key;
233 strbuf_write(buf->str, &name, -1);
234 }else if(key_type == DO_DELETE) {
235 TRACE("Deleting %s\n", debugstr_w(buf->str));
236 RegDeleteTreeW(parent_key, buf->str);
237 }else {
238 if(key_type == FORCE_REMOVE)
239 RegDeleteTreeW(parent_key, buf->str);
240 lres = RegCreateKeyW(parent_key, buf->str, &hkey);
241 if(lres != ERROR_SUCCESS) {
242 WARN("Could not create(open) key: %08lx\n", lres);
243 hres = HRESULT_FROM_WIN32(lres);
244 break;
247 }else if(key_type != IS_VAL && key_type != DO_DELETE) {
248 strbuf_write(buf->str, &name, -1);
249 lres = RegOpenKeyW(parent_key, buf->str, &hkey);
250 if(lres != ERROR_SUCCESS)
251 WARN("Could not open key %s: %08lx\n", debugstr_w(name.str), lres);
254 if(key_type != DO_DELETE && *iter == '=') {
255 iter++;
256 hres = get_word(&iter, buf);
257 if(FAILED(hres))
258 break;
259 if(buf->len != 1) {
260 WARN("Wrong registry type: %s\n", debugstr_w(buf->str));
261 hres = DISP_E_EXCEPTION;
262 break;
264 if(do_register) {
265 switch(buf->str[0]) {
266 case 's':
267 hres = get_word(&iter, buf);
268 if(FAILED(hres))
269 break;
270 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_SZ, (PBYTE)buf->str,
271 (lstrlenW(buf->str)+1)*sizeof(WCHAR));
272 if(lres != ERROR_SUCCESS) {
273 WARN("Could set value of key: %08lx\n", lres);
274 hres = HRESULT_FROM_WIN32(lres);
275 break;
277 break;
278 case 'd': {
279 DWORD dw;
280 hres = get_word(&iter, buf);
281 if(FAILED(hres))
282 break;
283 dw = wcstol(buf->str, NULL, 10);
284 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_DWORD,
285 (PBYTE)&dw, sizeof(dw));
286 if(lres != ERROR_SUCCESS) {
287 WARN("Could set value of key: %08lx\n", lres);
288 hres = HRESULT_FROM_WIN32(lres);
289 break;
291 break;
293 case 'b': {
294 BYTE *bytes;
295 DWORD count;
296 DWORD i;
297 hres = get_word(&iter, buf);
298 if(FAILED(hres))
299 break;
300 count = (lstrlenW(buf->str) + 1) / 2;
301 bytes = malloc(count);
302 if(bytes == NULL) {
303 hres = E_OUTOFMEMORY;
304 break;
306 for(i = 0; i < count && buf->str[2*i]; i++) {
307 int d1, d2;
308 if((d1 = xdigit_to_int(buf->str[2*i])) == -1 || (d2 = xdigit_to_int(buf->str[2*i + 1])) == -1) {
309 hres = E_FAIL;
310 break;
312 bytes[i] = (d1 << 4) | d2;
314 if(SUCCEEDED(hres)) {
315 lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_BINARY,
316 bytes, count);
317 if(lres != ERROR_SUCCESS) {
318 WARN("Could not set value of key: 0x%08lx\n", lres);
319 hres = HRESULT_FROM_WIN32(lres);
322 free(bytes);
323 break;
325 default:
326 WARN("Wrong resource type: %s\n", debugstr_w(buf->str));
327 hres = DISP_E_EXCEPTION;
329 if(FAILED(hres))
330 break;
331 }else {
332 if(*iter == '-')
333 iter++;
334 hres = get_word(&iter, buf);
335 if(FAILED(hres))
336 break;
338 }else if(key_type == IS_VAL) {
339 WARN("value not set!\n");
340 hres = DISP_E_EXCEPTION;
341 break;
344 if(key_type != IS_VAL && key_type != DO_DELETE && *iter == '{' && iswspace(iter[1])) {
345 hres = get_word(&iter, buf);
346 if(FAILED(hres))
347 break;
348 hres = do_process_key(&iter, hkey, buf, do_register);
349 if(FAILED(hres))
350 break;
353 TRACE("%x %x\n", do_register, key_type);
354 if(!do_register && (key_type == NORMAL || key_type == FORCE_REMOVE)) {
355 TRACE("Deleting %s\n", debugstr_w(name.str));
356 RegDeleteKeyW(parent_key, name.str);
359 if(hkey && key_type != IS_VAL)
360 RegCloseKey(hkey);
361 hkey = 0;
362 name.len = 0;
364 hres = get_word(&iter, buf);
365 if(FAILED(hres))
366 break;
369 free(name.str);
370 if(hkey && key_type != IS_VAL)
371 RegCloseKey(hkey);
372 *pstr = iter;
373 return hres;
376 static HRESULT do_process_root_key(LPCOLESTR data, BOOL do_register)
378 LPCOLESTR iter = data;
379 strbuf buf;
380 HRESULT hres;
381 unsigned int i;
383 strbuf_init(&buf);
384 hres = get_word(&iter, &buf);
385 if(FAILED(hres))
386 return hres;
388 while(*iter) {
389 if(!buf.len) {
390 WARN("ward.len == 0, failed\n");
391 hres = DISP_E_EXCEPTION;
392 break;
394 for(i=0; i<ARRAY_SIZE(root_keys); i++) {
395 if(!lstrcmpiW(buf.str, root_keys[i].name))
396 break;
398 if(i == ARRAY_SIZE(root_keys)) {
399 WARN("Wrong root key name: %s\n", debugstr_w(buf.str));
400 hres = DISP_E_EXCEPTION;
401 break;
403 hres = get_word(&iter, &buf);
404 if(FAILED(hres))
405 break;
406 if(buf.str[1] || buf.str[0] != '{') {
407 WARN("Failed, expected '{', got %s\n", debugstr_w(buf.str));
408 hres = DISP_E_EXCEPTION;
409 break;
411 hres = do_process_key(&iter, root_keys[i].key, &buf, do_register);
412 if(FAILED(hres)) {
413 WARN("Processing key failed: %08lx\n", hres);
414 break;
416 hres = get_word(&iter, &buf);
417 if(FAILED(hres))
418 break;
420 free(buf.str);
421 return hres;
424 static HRESULT string_register(Registrar *This, LPCOLESTR data, BOOL do_register)
426 strbuf buf;
427 HRESULT hres;
429 TRACE("(%p %s %x)\n", This, debugstr_w(data), do_register);
431 strbuf_init(&buf);
432 hres = do_preprocess(This, data, &buf);
433 if(FAILED(hres)) {
434 WARN("preprocessing failed!\n");
435 free(buf.str);
436 return hres;
439 hres = do_process_root_key(buf.str, do_register);
440 if(FAILED(hres) && do_register)
441 do_process_root_key(buf.str, FALSE);
443 free(buf.str);
444 return hres;
447 static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName,
448 LPCOLESTR szID, LPCOLESTR szType, BOOL do_register)
450 HINSTANCE hins;
451 HRSRC src;
452 LPSTR regstra;
453 LPWSTR regstrw;
454 DWORD len, reslen;
455 HRESULT hres;
457 hins = LoadLibraryExW(resFileName, NULL, LOAD_LIBRARY_AS_DATAFILE);
458 if(hins) {
459 src = FindResourceW(hins, szID, szType);
460 if(src) {
461 regstra = LoadResource(hins, src);
462 reslen = SizeofResource(hins, src);
463 if(regstra) {
464 len = MultiByteToWideChar(CP_ACP, 0, regstra, reslen, NULL, 0)+1;
465 regstrw = calloc(len, sizeof(WCHAR));
466 MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, len);
467 regstrw[len-1] = '\0';
469 hres = string_register(This, regstrw, do_register);
471 free(regstrw);
472 }else {
473 WARN("could not load resource\n");
474 hres = HRESULT_FROM_WIN32(GetLastError());
476 }else {
477 WARN("Could not find source\n");
478 hres = HRESULT_FROM_WIN32(GetLastError());
480 FreeLibrary(hins);
481 }else {
482 WARN("Could not load resource file\n");
483 hres = HRESULT_FROM_WIN32(GetLastError());
486 return hres;
489 static HRESULT file_register(Registrar *This, LPCOLESTR fileName, BOOL do_register)
491 HANDLE file;
492 DWORD filelen, len;
493 LPWSTR regstrw;
494 LPSTR regstra;
495 HRESULT hres;
497 file = CreateFileW(fileName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
498 if(file != INVALID_HANDLE_VALUE) {
499 filelen = GetFileSize(file, NULL);
500 regstra = malloc(filelen);
501 if(ReadFile(file, regstra, filelen, NULL, NULL)) {
502 len = MultiByteToWideChar(CP_ACP, 0, regstra, filelen, NULL, 0)+1;
503 regstrw = calloc(len, sizeof(WCHAR));
504 MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, len);
505 regstrw[len-1] = '\0';
507 hres = string_register(This, regstrw, do_register);
509 free(regstrw);
510 }else {
511 WARN("Failed to read file %s\n", debugstr_w(fileName));
512 hres = HRESULT_FROM_WIN32(GetLastError());
514 free(regstra);
515 CloseHandle(file);
516 }else {
517 WARN("Could not open file %s\n", debugstr_w(fileName));
518 hres = HRESULT_FROM_WIN32(GetLastError());
521 return hres;
524 static HRESULT WINAPI Registrar_QueryInterface(IRegistrar *iface, REFIID riid, void **ppvObject)
526 TRACE("(%p)->(%s %p\n", iface, debugstr_guid(riid), ppvObject);
528 if(IsEqualGUID(&IID_IUnknown, riid)
529 || IsEqualGUID(&IID_IRegistrar, riid)
530 || IsEqualGUID(&IID_IRegistrarBase, riid)) {
531 IRegistrar_AddRef(iface);
532 *ppvObject = iface;
533 return S_OK;
535 return E_NOINTERFACE;
538 static ULONG WINAPI Registrar_AddRef(IRegistrar *iface)
540 Registrar *This = impl_from_IRegistrar(iface);
541 ULONG ref = InterlockedIncrement(&This->ref);
542 TRACE("(%p) ->%ld\n", This, ref);
543 return ref;
546 static ULONG WINAPI Registrar_Release(IRegistrar *iface)
548 Registrar *This = impl_from_IRegistrar(iface);
549 ULONG ref = InterlockedDecrement(&This->ref);
551 TRACE("(%p) ->%ld\n", This, ref);
552 if(!ref) {
553 IRegistrar_ClearReplacements(iface);
554 free(This);
556 return ref;
559 static HRESULT WINAPI Registrar_AddReplacement(IRegistrar *iface, LPCOLESTR Key, LPCOLESTR item)
561 Registrar *This = impl_from_IRegistrar(iface);
562 int len;
563 rep_list *new_rep;
565 TRACE("(%p)->(%s %s)\n", This, debugstr_w(Key), debugstr_w(item));
567 new_rep = malloc(sizeof(*new_rep));
569 new_rep->key_len = lstrlenW(Key);
570 new_rep->key = malloc((new_rep->key_len + 1) * sizeof(OLECHAR));
571 memcpy(new_rep->key, Key, (new_rep->key_len+1)*sizeof(OLECHAR));
573 len = lstrlenW(item)+1;
574 new_rep->item = malloc(len*sizeof(OLECHAR));
575 memcpy(new_rep->item, item, len*sizeof(OLECHAR));
577 new_rep->next = This->rep;
578 This->rep = new_rep;
580 return S_OK;
583 static HRESULT WINAPI Registrar_ClearReplacements(IRegistrar *iface)
585 Registrar *This = impl_from_IRegistrar(iface);
586 rep_list *iter, *iter2;
588 TRACE("(%p)\n", This);
590 if(!This->rep)
591 return S_OK;
593 iter = This->rep;
594 while(iter) {
595 iter2 = iter->next;
596 free(iter->key);
597 free(iter->item);
598 free(iter);
599 iter = iter2;
602 This->rep = NULL;
603 return S_OK;
606 static HRESULT WINAPI Registrar_ResourceRegisterSz(IRegistrar* iface, LPCOLESTR resFileName,
607 LPCOLESTR szID, LPCOLESTR szType)
609 Registrar *This = impl_from_IRegistrar(iface);
610 TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
611 return resource_register(This, resFileName, szID, szType, TRUE);
614 static HRESULT WINAPI Registrar_ResourceUnregisterSz(IRegistrar* iface, LPCOLESTR resFileName,
615 LPCOLESTR szID, LPCOLESTR szType)
617 Registrar *This = impl_from_IRegistrar(iface);
618 TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
619 return resource_register(This, resFileName, szID, szType, FALSE);
622 static HRESULT WINAPI Registrar_FileRegister(IRegistrar* iface, LPCOLESTR fileName)
624 Registrar *This = impl_from_IRegistrar(iface);
625 TRACE("(%p)->(%s)\n", This, debugstr_w(fileName));
626 return file_register(This, fileName, TRUE);
629 static HRESULT WINAPI Registrar_FileUnregister(IRegistrar* iface, LPCOLESTR fileName)
631 Registrar *This = impl_from_IRegistrar(iface);
632 FIXME("(%p)->(%s)\n", This, debugstr_w(fileName));
633 return file_register(This, fileName, FALSE);
636 static HRESULT WINAPI Registrar_StringRegister(IRegistrar* iface, LPCOLESTR data)
638 Registrar *This = impl_from_IRegistrar(iface);
639 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
640 return string_register(This, data, TRUE);
643 static HRESULT WINAPI Registrar_StringUnregister(IRegistrar* iface, LPCOLESTR data)
645 Registrar *This = impl_from_IRegistrar(iface);
646 TRACE("(%p)->(%s)\n", This, debugstr_w(data));
647 return string_register(This, data, FALSE);
650 static HRESULT WINAPI Registrar_ResourceRegister(IRegistrar* iface, LPCOLESTR resFileName,
651 UINT nID, LPCOLESTR szType)
653 Registrar *This = impl_from_IRegistrar(iface);
654 TRACE("(%p)->(%s %d %s)\n", iface, debugstr_w(resFileName), nID, debugstr_w(szType));
655 return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, TRUE);
658 static HRESULT WINAPI Registrar_ResourceUnregister(IRegistrar* iface, LPCOLESTR resFileName,
659 UINT nID, LPCOLESTR szType)
661 Registrar *This = impl_from_IRegistrar(iface);
662 TRACE("(%p)->(%s %d %s)\n", This, debugstr_w(resFileName), nID, debugstr_w(szType));
663 return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, FALSE);
666 static const IRegistrarVtbl RegistrarVtbl = {
667 Registrar_QueryInterface,
668 Registrar_AddRef,
669 Registrar_Release,
670 Registrar_AddReplacement,
671 Registrar_ClearReplacements,
672 Registrar_ResourceRegisterSz,
673 Registrar_ResourceUnregisterSz,
674 Registrar_FileRegister,
675 Registrar_FileUnregister,
676 Registrar_StringRegister,
677 Registrar_StringUnregister,
678 Registrar_ResourceRegister,
679 Registrar_ResourceUnregister,
682 /***********************************************************************
683 * AtlCreateRegistrar [atl100.@]
685 HRESULT WINAPI AtlCreateRegistrar(IRegistrar **ret)
687 Registrar *registrar;
689 registrar = calloc(1, sizeof(*registrar));
690 if(!registrar)
691 return E_OUTOFMEMORY;
693 registrar->IRegistrar_iface.lpVtbl = &RegistrarVtbl;
694 registrar->ref = 1;
696 *ret = &registrar->IRegistrar_iface;
697 return S_OK;
700 /***********************************************************************
701 * AtlUpdateRegistryFromResourceD [atl100.@]
703 HRESULT WINAPI AtlUpdateRegistryFromResourceD(HINSTANCE inst, LPCOLESTR res,
704 BOOL bRegister, struct _ATL_REGMAP_ENTRY *pMapEntries, IRegistrar *pReg)
706 const struct _ATL_REGMAP_ENTRY *iter;
707 WCHAR module_name[MAX_PATH];
708 IRegistrar *registrar;
709 HRESULT hres;
711 if(!GetModuleFileNameW(inst, module_name, MAX_PATH)) {
712 FIXME("hinst %p: did not get module name\n", inst);
713 return E_FAIL;
716 TRACE("%p (%s), %s, %d, %p, %p\n", inst, debugstr_w(module_name),
717 debugstr_w(res), bRegister, pMapEntries, pReg);
719 if(pReg) {
720 registrar = pReg;
721 }else {
722 hres = AtlCreateRegistrar(&registrar);
723 if(FAILED(hres))
724 return hres;
727 IRegistrar_AddReplacement(registrar, L"MODULE", module_name);
729 for (iter = pMapEntries; iter && iter->szKey; iter++)
730 IRegistrar_AddReplacement(registrar, iter->szKey, iter->szData);
732 if(bRegister)
733 hres = IRegistrar_ResourceRegisterSz(registrar, module_name, res, L"REGISTRY");
734 else
735 hres = IRegistrar_ResourceUnregisterSz(registrar, module_name, res, L"REGISTRY");
737 if(registrar != pReg)
738 IRegistrar_Release(registrar);
739 return hres;