Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2005 Jacek Caban |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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 |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 16 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | |
| 20 | #include <stdarg.h> |
| 21 | |
| 22 | #define COBJMACROS |
| 23 | |
| 24 | #include "windef.h" |
| 25 | #include "winbase.h" |
| 26 | #include "winuser.h" |
| 27 | #include "winreg.h" |
| 28 | #include "objbase.h" |
| 29 | #include "oaidl.h" |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 30 | |
| 31 | #define ATL_INITGUID |
| 32 | #include "atliface.h" |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 33 | #include "atlbase.h" |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 34 | |
| 35 | #include "wine/debug.h" |
| 36 | #include "wine/unicode.h" |
| 37 | |
| 38 | WINE_DEFAULT_DEBUG_CHANNEL(atl); |
| 39 | |
Andrew Talbot | f6c09a2 | 2006-12-04 18:41:28 +0000 | [diff] [blame] | 40 | static LONG dll_count; |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 41 | |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 42 | /************************************************************** |
| 43 | * ATLRegistrar implementation |
| 44 | */ |
| 45 | |
Dmitry Timoshkov | 0be2a96 | 2006-12-14 22:46:31 +0800 | [diff] [blame] | 46 | static const struct { |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 47 | WCHAR name[22]; |
| 48 | HKEY key; |
| 49 | } root_keys[] = { |
| 50 | {{'H','K','E','Y','_','C','L','A','S','S','E','S','_','R','O','O','T',0}, |
| 51 | HKEY_CLASSES_ROOT}, |
| 52 | {{'H','K','E','Y','_','C','U','R','R','E','N','T','_','U','S','E','R',0}, |
| 53 | HKEY_CURRENT_USER}, |
| 54 | {{'H','K','E','Y','_','L','O','C','A','L','_','M','A','C','H','I','N','E',0}, |
| 55 | HKEY_LOCAL_MACHINE}, |
| 56 | {{'H','K','E','Y','_','U','S','E','R','S',0}, |
| 57 | HKEY_USERS}, |
| 58 | {{'H','K','E','Y','_','P','E','R','F','O','R','M','A','N','C','E','_','D','A','T','A',0}, |
| 59 | HKEY_PERFORMANCE_DATA}, |
| 60 | {{'H','K','E','Y','_','D','Y','N','_','D','A','T','A',0}, |
| 61 | HKEY_DYN_DATA}, |
| 62 | {{'H','K','E','Y','_','C','U','R','R','E','N','T','_','C','O','N','F','I','G',0}, |
| 63 | HKEY_CURRENT_CONFIG}, |
| 64 | {{'H','K','C','R',0}, HKEY_CLASSES_ROOT}, |
| 65 | {{'H','K','C','U',0}, HKEY_CURRENT_USER}, |
| 66 | {{'H','K','L','M',0}, HKEY_LOCAL_MACHINE}, |
| 67 | {{'H','K','U',0}, HKEY_USERS}, |
| 68 | {{'H','K','P','D',0}, HKEY_PERFORMANCE_DATA}, |
| 69 | {{'H','K','D','D',0}, HKEY_DYN_DATA}, |
| 70 | {{'H','K','C','C',0}, HKEY_CURRENT_CONFIG} |
| 71 | }; |
| 72 | |
| 73 | typedef struct rep_list_str { |
| 74 | LPOLESTR key; |
| 75 | LPOLESTR item; |
| 76 | int key_len; |
| 77 | struct rep_list_str *next; |
| 78 | } rep_list; |
| 79 | |
| 80 | typedef struct { |
Dmitry Timoshkov | 4625628 | 2005-05-27 20:17:35 +0000 | [diff] [blame] | 81 | const IRegistrarVtbl *lpVtbl; |
Mike McCormack | 2d7ea23 | 2005-07-11 13:21:17 +0000 | [diff] [blame] | 82 | LONG ref; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 83 | rep_list *rep; |
| 84 | } Registrar; |
| 85 | |
| 86 | typedef struct { |
| 87 | LPOLESTR str; |
| 88 | DWORD alloc; |
| 89 | DWORD len; |
| 90 | } strbuf; |
| 91 | |
| 92 | static void strbuf_init(strbuf *buf) |
| 93 | { |
| 94 | buf->str = HeapAlloc(GetProcessHeap(), 0, 128*sizeof(WCHAR)); |
| 95 | buf->alloc = 128; |
| 96 | buf->len = 0; |
| 97 | } |
| 98 | |
| 99 | static void strbuf_write(LPCOLESTR str, strbuf *buf, int len) |
| 100 | { |
| 101 | if(len == -1) |
| 102 | len = lstrlenW(str); |
| 103 | if(buf->len+len+1 >= buf->alloc) { |
| 104 | buf->alloc = (buf->len+len)<<1; |
| 105 | buf->str = HeapReAlloc(GetProcessHeap(), 0, buf->str, buf->alloc*sizeof(WCHAR)); |
| 106 | } |
| 107 | memcpy(buf->str+buf->len, str, len*sizeof(OLECHAR)); |
| 108 | buf->len += len; |
| 109 | buf->str[buf->len] = '\0'; |
| 110 | } |
| 111 | |
| 112 | static HRESULT get_word(LPCOLESTR *str, strbuf *buf) |
| 113 | { |
| 114 | LPCOLESTR iter, iter2 = *str; |
| 115 | |
| 116 | buf->len = 0; |
| 117 | buf->str[0] = '\0'; |
| 118 | |
| 119 | while(isspaceW(*iter2)) |
| 120 | iter2++; |
| 121 | iter = iter2; |
| 122 | if(!*iter) { |
| 123 | *str = iter; |
| 124 | return S_OK; |
| 125 | } |
| 126 | |
Jacek Caban | e1b644b | 2005-11-18 12:04:53 +0000 | [diff] [blame] | 127 | if(*iter == '}' || *iter == '=') { |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 128 | strbuf_write(iter++, buf, 1); |
| 129 | }else if(*iter == '\'') { |
| 130 | iter2 = ++iter; |
| 131 | iter = strchrW(iter, '\''); |
| 132 | if(!iter) { |
| 133 | WARN("Unexpected end of script\n"); |
| 134 | *str = iter; |
| 135 | return DISP_E_EXCEPTION; |
| 136 | } |
| 137 | strbuf_write(iter2, buf, iter-iter2); |
| 138 | iter++; |
| 139 | }else { |
| 140 | while(*iter && !isspaceW(*iter)) |
| 141 | iter++; |
| 142 | strbuf_write(iter2, buf, iter-iter2); |
| 143 | } |
| 144 | |
| 145 | while(isspaceW(*iter)) |
| 146 | iter++; |
| 147 | *str = iter; |
| 148 | return S_OK; |
| 149 | } |
| 150 | |
Andrew Talbot | 51bb7d1 | 2007-04-02 22:50:14 +0100 | [diff] [blame] | 151 | static HRESULT do_preprocess(const Registrar *This, LPCOLESTR data, strbuf *buf) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 152 | { |
| 153 | LPCOLESTR iter, iter2 = data; |
| 154 | rep_list *rep_iter; |
| 155 | static const WCHAR wstr[] = {'%',0}; |
| 156 | |
| 157 | iter = strchrW(data, '%'); |
| 158 | while(iter) { |
| 159 | strbuf_write(iter2, buf, iter-iter2); |
| 160 | |
| 161 | iter2 = ++iter; |
| 162 | if(!*iter2) |
| 163 | return DISP_E_EXCEPTION; |
| 164 | iter = strchrW(iter2, '%'); |
| 165 | if(!iter) |
| 166 | return DISP_E_EXCEPTION; |
| 167 | |
| 168 | if(iter == iter2) { |
| 169 | strbuf_write(wstr, buf, 1); |
| 170 | }else { |
| 171 | for(rep_iter = This->rep; rep_iter; rep_iter = rep_iter->next) { |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 172 | if(rep_iter->key_len == iter-iter2 |
| 173 | && !memicmpW(iter2, rep_iter->key, rep_iter->key_len)) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 174 | break; |
| 175 | } |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 176 | if(!rep_iter) { |
| 177 | WARN("Could not find replacement: %s\n", debugstr_wn(iter2, iter-iter2)); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 178 | return DISP_E_EXCEPTION; |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 179 | } |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 180 | |
| 181 | strbuf_write(rep_iter->item, buf, -1); |
| 182 | } |
| 183 | |
| 184 | iter2 = ++iter; |
| 185 | iter = strchrW(iter, '%'); |
| 186 | } |
| 187 | |
| 188 | strbuf_write(iter2, buf, -1); |
| 189 | TRACE("%s\n", debugstr_w(buf->str)); |
| 190 | |
| 191 | return S_OK; |
| 192 | } |
| 193 | |
| 194 | static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOOL do_register) |
| 195 | { |
| 196 | LPCOLESTR iter = *pstr; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 197 | HRESULT hres; |
| 198 | LONG lres; |
| 199 | HKEY hkey = 0; |
| 200 | strbuf name; |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 201 | |
| 202 | enum { |
| 203 | NORMAL, |
| 204 | NO_REMOVE, |
| 205 | IS_VAL, |
| 206 | FORCE_REMOVE, |
| 207 | DO_DELETE |
| 208 | } key_type = NORMAL; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 209 | |
| 210 | static const WCHAR wstrNoRemove[] = {'N','o','R','e','m','o','v','e',0}; |
| 211 | static const WCHAR wstrForceRemove[] = {'F','o','r','c','e','R','e','m','o','v','e',0}; |
| 212 | static const WCHAR wstrDelete[] = {'D','e','l','e','t','e',0}; |
| 213 | static const WCHAR wstrval[] = {'v','a','l',0}; |
| 214 | |
| 215 | iter = *pstr; |
| 216 | hres = get_word(&iter, buf); |
| 217 | if(FAILED(hres)) |
| 218 | return hres; |
| 219 | strbuf_init(&name); |
| 220 | |
| 221 | while(buf->str[1] || buf->str[0] != '}') { |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 222 | key_type = NORMAL; |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 223 | if(!lstrcmpiW(buf->str, wstrNoRemove)) |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 224 | key_type = NO_REMOVE; |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 225 | else if(!lstrcmpiW(buf->str, wstrForceRemove)) |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 226 | key_type = FORCE_REMOVE; |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 227 | else if(!lstrcmpiW(buf->str, wstrval)) |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 228 | key_type = IS_VAL; |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 229 | else if(!lstrcmpiW(buf->str, wstrDelete)) |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 230 | key_type = DO_DELETE; |
| 231 | |
| 232 | if(key_type != NORMAL) { |
| 233 | hres = get_word(&iter, buf); |
| 234 | if(FAILED(hres)) |
| 235 | break; |
| 236 | } |
| 237 | TRACE("name = %s\n", debugstr_w(buf->str)); |
| 238 | |
| 239 | if(do_register) { |
| 240 | if(key_type == IS_VAL) { |
| 241 | hkey = parent_key; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 242 | strbuf_write(buf->str, &name, -1); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 243 | }else if(key_type == DO_DELETE) { |
| 244 | TRACE("Deleting %s\n", debugstr_w(buf->str)); |
Ricardo Filipe | d27fa4f | 2008-11-19 21:32:29 +0000 | [diff] [blame] | 245 | RegDeleteTreeW(parent_key, buf->str); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 246 | }else { |
| 247 | if(key_type == FORCE_REMOVE) |
Paul Vriens | 4f49655 | 2007-08-22 11:05:35 +0200 | [diff] [blame] | 248 | RegDeleteTreeW(parent_key, buf->str); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 249 | lres = RegCreateKeyW(parent_key, buf->str, &hkey); |
| 250 | if(lres != ERROR_SUCCESS) { |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 251 | WARN("Could not create(open) key: %08x\n", lres); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 252 | hres = HRESULT_FROM_WIN32(lres); |
| 253 | break; |
| 254 | } |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 255 | } |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 256 | }else if(key_type != IS_VAL && key_type != DO_DELETE) { |
| 257 | strbuf_write(buf->str, &name, -1); |
| 258 | lres = RegOpenKeyW(parent_key, buf->str, &hkey); |
| 259 | if(lres != ERROR_SUCCESS) |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 260 | WARN("Could not open key %s: %08x\n", debugstr_w(name.str), lres); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | if(key_type != DO_DELETE && *iter == '=') { |
| 264 | iter++; |
| 265 | hres = get_word(&iter, buf); |
| 266 | if(FAILED(hres)) |
| 267 | break; |
| 268 | if(buf->len != 1) { |
| 269 | WARN("Wrong registry type: %s\n", debugstr_w(buf->str)); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 270 | hres = DISP_E_EXCEPTION; |
| 271 | break; |
| 272 | } |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 273 | if(do_register) { |
| 274 | switch(buf->str[0]) { |
| 275 | case 's': |
| 276 | hres = get_word(&iter, buf); |
| 277 | if(FAILED(hres)) |
| 278 | break; |
| 279 | lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_SZ, (PBYTE)buf->str, |
| 280 | (lstrlenW(buf->str)+1)*sizeof(WCHAR)); |
| 281 | if(lres != ERROR_SUCCESS) { |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 282 | WARN("Could set value of key: %08x\n", lres); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 283 | hres = HRESULT_FROM_WIN32(lres); |
| 284 | break; |
| 285 | } |
| 286 | break; |
| 287 | case 'd': { |
Andrew Talbot | 90b1d7a | 2006-10-17 22:55:43 +0100 | [diff] [blame] | 288 | WCHAR *end; |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 289 | DWORD dw; |
| 290 | if(*iter == '0' && iter[1] == 'x') { |
| 291 | iter += 2; |
Andrew Talbot | 90b1d7a | 2006-10-17 22:55:43 +0100 | [diff] [blame] | 292 | dw = strtolW(iter, &end, 16); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 293 | }else { |
Andrew Talbot | 90b1d7a | 2006-10-17 22:55:43 +0100 | [diff] [blame] | 294 | dw = strtolW(iter, &end, 10); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 295 | } |
Andrew Talbot | 90b1d7a | 2006-10-17 22:55:43 +0100 | [diff] [blame] | 296 | iter = end; |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 297 | lres = RegSetValueExW(hkey, name.len ? name.str : NULL, 0, REG_DWORD, |
| 298 | (PBYTE)&dw, sizeof(dw)); |
| 299 | if(lres != ERROR_SUCCESS) { |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 300 | WARN("Could set value of key: %08x\n", lres); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 301 | hres = HRESULT_FROM_WIN32(lres); |
| 302 | break; |
| 303 | } |
| 304 | break; |
| 305 | } |
| 306 | default: |
| 307 | WARN("Wrong resource type: %s\n", debugstr_w(buf->str)); |
| 308 | hres = DISP_E_EXCEPTION; |
| 309 | }; |
| 310 | if(FAILED(hres)) |
| 311 | break; |
| 312 | }else { |
| 313 | if(*iter == '-') |
| 314 | iter++; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 315 | hres = get_word(&iter, buf); |
| 316 | if(FAILED(hres)) |
| 317 | break; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 318 | } |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 319 | }else if(key_type == IS_VAL) { |
| 320 | WARN("value not set!\n"); |
| 321 | hres = DISP_E_EXCEPTION; |
| 322 | break; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 323 | } |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 324 | |
Jacek Caban | e1b644b | 2005-11-18 12:04:53 +0000 | [diff] [blame] | 325 | if(key_type != IS_VAL && key_type != DO_DELETE && *iter == '{' && isspaceW(iter[1])) { |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 326 | hres = get_word(&iter, buf); |
| 327 | if(FAILED(hres)) |
| 328 | break; |
| 329 | hres = do_process_key(&iter, hkey, buf, do_register); |
| 330 | if(FAILED(hres)) |
| 331 | break; |
| 332 | } |
| 333 | |
| 334 | TRACE("%x %x\n", do_register, key_type); |
| 335 | if(!do_register && (key_type == NORMAL || key_type == FORCE_REMOVE)) { |
| 336 | TRACE("Deleting %s\n", debugstr_w(name.str)); |
| 337 | RegDeleteKeyW(parent_key, name.str); |
| 338 | } |
| 339 | |
| 340 | if(hkey && key_type != IS_VAL) |
| 341 | RegCloseKey(hkey); |
| 342 | hkey = 0; |
| 343 | name.len = 0; |
| 344 | |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 345 | hres = get_word(&iter, buf); |
| 346 | if(FAILED(hres)) |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | HeapFree(GetProcessHeap(), 0, name.str); |
Jacek Caban | f362a3f | 2005-03-18 10:25:29 +0000 | [diff] [blame] | 351 | if(hkey && key_type != IS_VAL) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 352 | RegCloseKey(hkey); |
| 353 | *pstr = iter; |
| 354 | return hres; |
| 355 | } |
| 356 | |
| 357 | static HRESULT do_process_root_key(LPCOLESTR data, BOOL do_register) |
| 358 | { |
| 359 | LPCOLESTR iter = data; |
| 360 | strbuf buf; |
| 361 | HRESULT hres = S_OK; |
Michael Stefaniuc | 90c0ffd | 2007-02-13 00:13:00 +0100 | [diff] [blame] | 362 | unsigned int i; |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 363 | |
| 364 | strbuf_init(&buf); |
| 365 | hres = get_word(&iter, &buf); |
| 366 | if(FAILED(hres)) |
| 367 | return hres; |
| 368 | |
| 369 | while(*iter) { |
| 370 | if(!buf.len) { |
| 371 | WARN("ward.len == 0, failed\n"); |
| 372 | hres = DISP_E_EXCEPTION; |
| 373 | break; |
| 374 | } |
| 375 | for(i=0; i<sizeof(root_keys)/sizeof(root_keys[0]); i++) { |
Jacek Caban | fbe35b6 | 2005-03-21 10:52:04 +0000 | [diff] [blame] | 376 | if(!lstrcmpiW(buf.str, root_keys[i].name)) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 377 | break; |
| 378 | } |
| 379 | if(i == sizeof(root_keys)/sizeof(root_keys[0])) { |
| 380 | WARN("Wrong root key name: %s\n", debugstr_w(buf.str)); |
| 381 | hres = DISP_E_EXCEPTION; |
| 382 | break; |
| 383 | } |
| 384 | hres = get_word(&iter, &buf); |
| 385 | if(FAILED(hres)) |
| 386 | break; |
| 387 | if(buf.str[1] || buf.str[0] != '{') { |
| 388 | WARN("Failed, expected '{', got %s\n", debugstr_w(buf.str)); |
| 389 | hres = DISP_E_EXCEPTION; |
| 390 | break; |
| 391 | } |
| 392 | hres = do_process_key(&iter, root_keys[i].key, &buf, do_register); |
| 393 | if(FAILED(hres)) { |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 394 | WARN("Processing key failed: %08x\n", hres); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 395 | break; |
| 396 | } |
| 397 | hres = get_word(&iter, &buf); |
| 398 | if(FAILED(hres)) |
| 399 | break; |
| 400 | } |
| 401 | HeapFree(GetProcessHeap(), 0, buf.str); |
| 402 | return hres; |
| 403 | } |
| 404 | |
| 405 | static HRESULT string_register(Registrar *This, LPCOLESTR data, BOOL do_register) |
| 406 | { |
| 407 | strbuf buf; |
| 408 | HRESULT hres; |
| 409 | |
| 410 | TRACE("(%p %s %x)\n", This, debugstr_w(data), do_register); |
| 411 | |
| 412 | strbuf_init(&buf); |
| 413 | hres = do_preprocess(This, data, &buf); |
| 414 | if(FAILED(hres)) { |
| 415 | WARN("preprocessing failed!\n"); |
| 416 | HeapFree(GetProcessHeap(), 0, buf.str); |
| 417 | return hres; |
| 418 | } |
| 419 | |
| 420 | hres = do_process_root_key(buf.str, do_register); |
| 421 | if(FAILED(hres) && do_register) |
| 422 | do_process_root_key(buf.str, FALSE); |
| 423 | |
| 424 | HeapFree(GetProcessHeap(), 0, buf.str); |
| 425 | return hres; |
| 426 | } |
| 427 | |
| 428 | static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName, |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 429 | LPCOLESTR szID, LPCOLESTR szType, BOOL do_register) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 430 | { |
| 431 | HINSTANCE hins; |
| 432 | HRSRC src; |
| 433 | LPSTR regstra; |
| 434 | LPWSTR regstrw; |
| 435 | DWORD len, reslen; |
| 436 | HRESULT hres; |
| 437 | |
| 438 | hins = LoadLibraryExW(resFileName, NULL, LOAD_LIBRARY_AS_DATAFILE); |
| 439 | if(hins) { |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 440 | src = FindResourceW(hins, szID, szType); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 441 | if(src) { |
Michael Stefaniuc | fa1d049 | 2008-12-05 07:50:43 +0100 | [diff] [blame] | 442 | regstra = LoadResource(hins, src); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 443 | reslen = SizeofResource(hins, src); |
| 444 | if(regstra) { |
| 445 | len = MultiByteToWideChar(CP_ACP, 0, regstra, reslen, NULL, 0)+1; |
| 446 | regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR)); |
Marcus Meissner | d65bd8f | 2009-02-04 20:33:40 +0100 | [diff] [blame] | 447 | MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, len); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 448 | regstrw[len-1] = '\0'; |
| 449 | |
| 450 | hres = string_register(This, regstrw, do_register); |
| 451 | |
| 452 | HeapFree(GetProcessHeap(), 0, regstrw); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 453 | }else { |
| 454 | WARN("could not load resource\n"); |
| 455 | hres = HRESULT_FROM_WIN32(GetLastError()); |
| 456 | } |
| 457 | }else { |
| 458 | WARN("Could not find source\n"); |
| 459 | hres = HRESULT_FROM_WIN32(GetLastError()); |
| 460 | } |
| 461 | FreeLibrary(hins); |
| 462 | }else { |
| 463 | WARN("Could not load resource file\n"); |
| 464 | hres = HRESULT_FROM_WIN32(GetLastError()); |
| 465 | } |
| 466 | |
| 467 | return hres; |
| 468 | } |
| 469 | |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 470 | static HRESULT file_register(Registrar *This, LPCOLESTR fileName, BOOL do_register) |
| 471 | { |
| 472 | HANDLE file; |
| 473 | DWORD filelen, len; |
| 474 | LPWSTR regstrw; |
| 475 | LPSTR regstra; |
| 476 | LRESULT lres; |
| 477 | HRESULT hres; |
| 478 | |
| 479 | file = CreateFileW(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL); |
Jacek Caban | ecac3c1 | 2007-03-07 00:05:15 +0100 | [diff] [blame] | 480 | if(file != INVALID_HANDLE_VALUE) { |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 481 | filelen = GetFileSize(file, NULL); |
| 482 | regstra = HeapAlloc(GetProcessHeap(), 0, filelen); |
| 483 | lres = ReadFile(file, regstra, filelen, NULL, NULL); |
| 484 | if(lres == ERROR_SUCCESS) { |
| 485 | len = MultiByteToWideChar(CP_ACP, 0, regstra, filelen, NULL, 0)+1; |
| 486 | regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR)); |
Marcus Meissner | d65bd8f | 2009-02-04 20:33:40 +0100 | [diff] [blame] | 487 | MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, len); |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 488 | regstrw[len-1] = '\0'; |
| 489 | |
| 490 | hres = string_register(This, regstrw, do_register); |
| 491 | |
| 492 | HeapFree(GetProcessHeap(), 0, regstrw); |
| 493 | }else { |
| 494 | WARN("Failed to read faile\n"); |
| 495 | hres = HRESULT_FROM_WIN32(lres); |
| 496 | } |
| 497 | HeapFree(GetProcessHeap(), 0, regstra); |
| 498 | CloseHandle(file); |
| 499 | }else { |
| 500 | WARN("Could not open file\n"); |
| 501 | hres = HRESULT_FROM_WIN32(GetLastError()); |
| 502 | } |
| 503 | |
| 504 | return hres; |
| 505 | } |
| 506 | |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 507 | static HRESULT WINAPI Registrar_QueryInterface(IRegistrar *iface, REFIID riid, void **ppvObject) |
| 508 | { |
| 509 | TRACE("(%p)->(%s %p\n", iface, debugstr_guid(riid), ppvObject); |
| 510 | |
| 511 | if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IRegistrar, riid)) { |
| 512 | IRegistrar_AddRef(iface); |
| 513 | *ppvObject = iface; |
| 514 | return S_OK; |
| 515 | } |
| 516 | return E_NOINTERFACE; |
| 517 | } |
| 518 | |
| 519 | static ULONG WINAPI Registrar_AddRef(IRegistrar *iface) |
| 520 | { |
| 521 | Registrar *This = (Registrar*)iface; |
| 522 | ULONG ref = InterlockedIncrement(&This->ref); |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 523 | TRACE("(%p) ->%d\n", This, ref); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 524 | return ref; |
| 525 | } |
| 526 | |
| 527 | static ULONG WINAPI Registrar_Release(IRegistrar *iface) |
| 528 | { |
| 529 | Registrar *This = (Registrar*)iface; |
| 530 | ULONG ref = InterlockedDecrement(&This->ref); |
| 531 | |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 532 | TRACE("(%p) ->%d\n", This, ref); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 533 | if(!ref) { |
| 534 | IRegistrar_ClearReplacements(iface); |
| 535 | HeapFree(GetProcessHeap(), 0, This); |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 536 | InterlockedDecrement(&dll_count); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 537 | } |
| 538 | return ref; |
| 539 | } |
| 540 | |
| 541 | static HRESULT WINAPI Registrar_AddReplacement(IRegistrar *iface, LPCOLESTR Key, LPCOLESTR item) |
| 542 | { |
| 543 | Registrar *This = (Registrar*)iface; |
| 544 | int len; |
| 545 | rep_list *new_rep; |
| 546 | |
| 547 | TRACE("(%p)->(%s %s)\n", This, debugstr_w(Key), debugstr_w(item)); |
| 548 | |
| 549 | new_rep = HeapAlloc(GetProcessHeap(), 0, sizeof(rep_list)); |
| 550 | |
| 551 | new_rep->key_len = lstrlenW(Key); |
| 552 | new_rep->key = HeapAlloc(GetProcessHeap(), 0, new_rep->key_len*sizeof(OLECHAR)+1); |
| 553 | memcpy(new_rep->key, Key, (new_rep->key_len+1)*sizeof(OLECHAR)); |
| 554 | |
| 555 | len = lstrlenW(item)+1; |
| 556 | new_rep->item = HeapAlloc(GetProcessHeap(), 0, len*sizeof(OLECHAR)); |
| 557 | memcpy(new_rep->item, item, len*sizeof(OLECHAR)); |
| 558 | |
| 559 | new_rep->next = This->rep; |
| 560 | This->rep = new_rep; |
| 561 | |
| 562 | return S_OK; |
| 563 | } |
| 564 | |
| 565 | static HRESULT WINAPI Registrar_ClearReplacements(IRegistrar *iface) |
| 566 | { |
| 567 | Registrar *This = (Registrar*)iface; |
| 568 | rep_list *iter, *iter2; |
| 569 | |
| 570 | TRACE("(%p)\n", This); |
| 571 | |
| 572 | if(!This->rep) |
| 573 | return S_OK; |
| 574 | |
| 575 | iter = This->rep; |
| 576 | while(iter) { |
| 577 | iter2 = iter->next; |
| 578 | HeapFree(GetProcessHeap(), 0, iter->key); |
| 579 | HeapFree(GetProcessHeap(), 0, iter->item); |
| 580 | HeapFree(GetProcessHeap(), 0, iter); |
| 581 | iter = iter2; |
| 582 | } |
| 583 | |
| 584 | This->rep = NULL; |
| 585 | return S_OK; |
| 586 | } |
| 587 | |
| 588 | static HRESULT WINAPI Registrar_ResourceRegisterSz(IRegistrar* iface, LPCOLESTR resFileName, |
| 589 | LPCOLESTR szID, LPCOLESTR szType) |
| 590 | { |
| 591 | Registrar *This = (Registrar*)iface; |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 592 | TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType)); |
| 593 | return resource_register(This, resFileName, szID, szType, TRUE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | static HRESULT WINAPI Registrar_ResourceUnregisterSz(IRegistrar* iface, LPCOLESTR resFileName, |
| 597 | LPCOLESTR szID, LPCOLESTR szType) |
| 598 | { |
| 599 | Registrar *This = (Registrar*)iface; |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 600 | TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType)); |
| 601 | return resource_register(This, resFileName, szID, szType, FALSE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | static HRESULT WINAPI Registrar_FileRegister(IRegistrar* iface, LPCOLESTR fileName) |
| 605 | { |
| 606 | Registrar *This = (Registrar*)iface; |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 607 | TRACE("(%p)->(%s)\n", This, debugstr_w(fileName)); |
| 608 | return file_register(This, fileName, TRUE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static HRESULT WINAPI Registrar_FileUnregister(IRegistrar* iface, LPCOLESTR fileName) |
| 612 | { |
| 613 | Registrar *This = (Registrar*)iface; |
| 614 | FIXME("(%p)->(%s)\n", This, debugstr_w(fileName)); |
Jacek Caban | e10b584 | 2005-03-19 17:04:13 +0000 | [diff] [blame] | 615 | return file_register(This, fileName, FALSE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | static HRESULT WINAPI Registrar_StringRegister(IRegistrar* iface, LPCOLESTR data) |
| 619 | { |
| 620 | Registrar *This = (Registrar*)iface; |
| 621 | TRACE("(%p)->(%s)\n", This, debugstr_w(data)); |
| 622 | return string_register(This, data, TRUE); |
| 623 | } |
| 624 | |
| 625 | static HRESULT WINAPI Registrar_StringUnregister(IRegistrar* iface, LPCOLESTR data) |
| 626 | { |
| 627 | Registrar *This = (Registrar*)iface; |
| 628 | TRACE("(%p)->(%s)\n", This, debugstr_w(data)); |
| 629 | return string_register(This, data, FALSE); |
| 630 | } |
| 631 | |
| 632 | static HRESULT WINAPI Registrar_ResourceRegister(IRegistrar* iface, LPCOLESTR resFileName, |
| 633 | UINT nID, LPCOLESTR szType) |
| 634 | { |
| 635 | Registrar *This = (Registrar*)iface; |
| 636 | TRACE("(%p)->(%s %d %s)\n", iface, debugstr_w(resFileName), nID, debugstr_w(szType)); |
Kevin Koltzau | dbfac2e | 2005-08-22 10:18:17 +0000 | [diff] [blame] | 637 | return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, TRUE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | static HRESULT WINAPI Registrar_ResourceUnregister(IRegistrar* iface, LPCOLESTR resFileName, |
| 641 | UINT nID, LPCOLESTR szType) |
| 642 | { |
| 643 | Registrar *This = (Registrar*)iface; |
| 644 | TRACE("(%p)->(%s %d %s)\n", This, debugstr_w(resFileName), nID, debugstr_w(szType)); |
Kevin Koltzau | dbfac2e | 2005-08-22 10:18:17 +0000 | [diff] [blame] | 645 | return resource_register(This, resFileName, MAKEINTRESOURCEW(nID), szType, FALSE); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 646 | } |
| 647 | |
Dmitry Timoshkov | 4625628 | 2005-05-27 20:17:35 +0000 | [diff] [blame] | 648 | static const IRegistrarVtbl RegistrarVtbl = { |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 649 | Registrar_QueryInterface, |
| 650 | Registrar_AddRef, |
| 651 | Registrar_Release, |
| 652 | Registrar_AddReplacement, |
| 653 | Registrar_ClearReplacements, |
| 654 | Registrar_ResourceRegisterSz, |
| 655 | Registrar_ResourceUnregisterSz, |
| 656 | Registrar_FileRegister, |
| 657 | Registrar_FileUnregister, |
| 658 | Registrar_StringRegister, |
| 659 | Registrar_StringUnregister, |
| 660 | Registrar_ResourceRegister, |
| 661 | Registrar_ResourceUnregister, |
| 662 | }; |
| 663 | |
Andrew Talbot | 51bb7d1 | 2007-04-02 22:50:14 +0100 | [diff] [blame] | 664 | static HRESULT Registrar_create(const IUnknown *pUnkOuter, REFIID riid, void **ppvObject) |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 665 | { |
| 666 | Registrar *ret; |
| 667 | |
| 668 | if(!IsEqualGUID(&IID_IUnknown, riid) && !IsEqualGUID(&IID_IRegistrar, riid)) |
| 669 | return E_NOINTERFACE; |
| 670 | |
| 671 | ret = HeapAlloc(GetProcessHeap(), 0, sizeof(Registrar)); |
| 672 | ret->lpVtbl = &RegistrarVtbl; |
| 673 | ret->ref = 1; |
| 674 | ret->rep = NULL; |
| 675 | *ppvObject = ret; |
| 676 | |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 677 | InterlockedIncrement(&dll_count); |
| 678 | |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 679 | return S_OK; |
| 680 | } |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 681 | |
| 682 | /************************************************************** |
| 683 | * ClassFactory implementation |
| 684 | */ |
| 685 | |
| 686 | static HRESULT WINAPI RegistrarCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppvObject) |
| 687 | { |
| 688 | TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject); |
| 689 | |
| 690 | if(IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IRegistrar, riid)) { |
| 691 | *ppvObject = iface; |
| 692 | return S_OK; |
| 693 | } |
| 694 | |
| 695 | return E_NOINTERFACE; |
| 696 | } |
| 697 | |
| 698 | static ULONG WINAPI RegistrarCF_AddRef(IClassFactory *iface) |
| 699 | { |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 700 | InterlockedIncrement(&dll_count); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 701 | return 2; |
| 702 | } |
| 703 | |
| 704 | static ULONG WINAPI RegistrarCF_Release(IClassFactory *iface) |
| 705 | { |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 706 | InterlockedDecrement(&dll_count); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 707 | return 1; |
| 708 | } |
| 709 | |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 710 | static HRESULT WINAPI RegistrarCF_CreateInstance(IClassFactory *iface, LPUNKNOWN pUnkOuter, |
| 711 | REFIID riid, void **ppvObject) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 712 | { |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 713 | TRACE("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppvObject); |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 714 | return Registrar_create(pUnkOuter, riid, ppvObject); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static HRESULT WINAPI RegistrarCF_LockServer(IClassFactory *iface, BOOL lock) |
| 718 | { |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 719 | TRACE("(%p)->(%x)\n", iface, lock); |
| 720 | |
| 721 | if(lock) |
| 722 | InterlockedIncrement(&dll_count); |
| 723 | else |
| 724 | InterlockedDecrement(&dll_count); |
| 725 | |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 726 | return S_OK; |
| 727 | } |
| 728 | |
| 729 | static const IClassFactoryVtbl IRegistrarCFVtbl = { |
| 730 | RegistrarCF_QueryInterface, |
| 731 | RegistrarCF_AddRef, |
| 732 | RegistrarCF_Release, |
| 733 | RegistrarCF_CreateInstance, |
| 734 | RegistrarCF_LockServer |
| 735 | }; |
| 736 | |
| 737 | static IClassFactory RegistrarCF = { &IRegistrarCFVtbl }; |
| 738 | |
| 739 | /************************************************************** |
Vincent BĂ©ron | 21e3ba8 | 2005-08-10 09:53:47 +0000 | [diff] [blame] | 740 | * DllGetClassObject (ATL.2) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 741 | */ |
Alexandre Julliard | d37f0ab | 2005-08-08 17:35:28 +0000 | [diff] [blame] | 742 | HRESULT WINAPI DllGetClassObject(REFCLSID clsid, REFIID riid, LPVOID *ppvObject) |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 743 | { |
Francois Gouget | 82babbe | 2006-10-05 11:11:03 +0200 | [diff] [blame] | 744 | TRACE("(%s %s %p)\n", debugstr_guid(clsid), debugstr_guid(riid), ppvObject); |
Jacek Caban | 544a1a2 | 2005-03-14 10:51:27 +0000 | [diff] [blame] | 745 | |
| 746 | if(IsEqualGUID(&CLSID_ATLRegistrar, clsid)) { |
| 747 | *ppvObject = &RegistrarCF; |
| 748 | return S_OK; |
| 749 | } |
| 750 | |
| 751 | FIXME("Not supported class %s\n", debugstr_guid(clsid)); |
| 752 | return CLASS_E_CLASSNOTAVAILABLE; |
| 753 | } |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 754 | |
| 755 | extern HINSTANCE hInst; |
| 756 | |
Rob Shearman | d51c1c7 | 2007-03-21 09:30:27 +0000 | [diff] [blame] | 757 | static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll, |
| 758 | LPCOLESTR wszId, BOOL do_register, |
| 759 | const struct _ATL_REGMAP_ENTRY* pMapEntries) |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 760 | { |
| 761 | WCHAR buf[MAX_PATH]; |
| 762 | HRESULT hres; |
Rob Shearman | c11ad1e | 2007-03-21 09:29:48 +0000 | [diff] [blame] | 763 | const struct _ATL_REGMAP_ENTRY *pMapEntry; |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 764 | |
| 765 | static const WCHAR wszModule[] = {'M','O','D','U','L','E',0}; |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 766 | static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0}; |
| 767 | static const WCHAR wszCLSID_ATLRegistrar[] = |
| 768 | {'C','L','S','I','D','_','A','T','L','R','e','g','i','s','t','r','a','r',0}; |
| 769 | |
Rob Shearman | d51c1c7 | 2007-03-21 09:30:27 +0000 | [diff] [blame] | 770 | if (!pRegistrar) |
| 771 | Registrar_create(NULL, &IID_IRegistrar, (void**)&pRegistrar); |
| 772 | |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 773 | IRegistrar_AddReplacement(pRegistrar, wszModule, wszDll); |
| 774 | |
Rob Shearman | c11ad1e | 2007-03-21 09:29:48 +0000 | [diff] [blame] | 775 | for (pMapEntry = pMapEntries; pMapEntry && pMapEntry->szKey; pMapEntry++) |
| 776 | IRegistrar_AddReplacement(pRegistrar, pMapEntry->szKey, pMapEntry->szData); |
| 777 | |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 778 | StringFromGUID2(&CLSID_ATLRegistrar, buf, sizeof(buf)/sizeof(buf[0])); |
| 779 | IRegistrar_AddReplacement(pRegistrar, wszCLSID_ATLRegistrar, buf); |
| 780 | |
| 781 | if(do_register) |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 782 | hres = IRegistrar_ResourceRegisterSz(pRegistrar, wszDll, wszId, wszRegistry); |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 783 | else |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 784 | hres = IRegistrar_ResourceUnregisterSz(pRegistrar, wszDll, wszId, wszRegistry); |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 785 | |
| 786 | IRegistrar_Release(pRegistrar); |
| 787 | return hres; |
| 788 | } |
| 789 | |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 790 | static HRESULT do_register_server(BOOL do_register) |
| 791 | { |
| 792 | static const WCHAR wszDll[] = {'a','t','l','.','d','l','l',0}; |
Rob Shearman | d51c1c7 | 2007-03-21 09:30:27 +0000 | [diff] [blame] | 793 | return do_register_dll_server(NULL, wszDll, MAKEINTRESOURCEW(101), do_register, NULL); |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /*********************************************************************** |
| 797 | * AtlModuleUpdateRegistryFromResourceD [ATL.@] |
| 798 | * |
| 799 | */ |
| 800 | HRESULT WINAPI AtlModuleUpdateRegistryFromResourceD(_ATL_MODULEW* pM, LPCOLESTR lpszRes, |
| 801 | BOOL bRegister, struct _ATL_REGMAP_ENTRY* pMapEntries, IRegistrar* pReg) |
| 802 | { |
| 803 | HINSTANCE lhInst = pM->m_hInst; |
| 804 | /* everything inside this function below this point |
| 805 | * should go into atl71.AtlUpdateRegistryFromResourceD |
| 806 | */ |
| 807 | WCHAR module_name[MAX_PATH]; |
| 808 | |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 809 | if(!GetModuleFileNameW(lhInst, module_name, MAX_PATH)) { |
Stefan Leichter | 80af494 | 2005-08-22 09:21:34 +0000 | [diff] [blame] | 810 | FIXME("hinst %p: did not get module name\n", |
| 811 | lhInst); |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 812 | return E_FAIL; |
| 813 | } |
| 814 | |
Stefan Leichter | 80af494 | 2005-08-22 09:21:34 +0000 | [diff] [blame] | 815 | TRACE("%p (%s), %s, %d, %p, %p\n", hInst, debugstr_w(module_name), |
| 816 | debugstr_w(lpszRes), bRegister, pMapEntries, pReg); |
| 817 | |
Rob Shearman | d51c1c7 | 2007-03-21 09:30:27 +0000 | [diff] [blame] | 818 | return do_register_dll_server(pReg, module_name, lpszRes, bRegister, pMapEntries); |
Stefan Leichter | 4663d5d | 2005-08-08 11:06:42 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 821 | /*********************************************************************** |
| 822 | * DllRegisterServer (ATL.@) |
| 823 | */ |
Alexandre Julliard | d37f0ab | 2005-08-08 17:35:28 +0000 | [diff] [blame] | 824 | HRESULT WINAPI DllRegisterServer(void) |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 825 | { |
| 826 | TRACE("\n"); |
| 827 | return do_register_server(TRUE); |
| 828 | } |
| 829 | |
| 830 | /*********************************************************************** |
| 831 | * DllRegisterServer (ATL.@) |
| 832 | */ |
Alexandre Julliard | d37f0ab | 2005-08-08 17:35:28 +0000 | [diff] [blame] | 833 | HRESULT WINAPI DllUnregisterServer(void) |
Jacek Caban | d12cb30 | 2005-03-16 19:53:41 +0000 | [diff] [blame] | 834 | { |
| 835 | TRACE("\n"); |
| 836 | return do_register_server(FALSE); |
| 837 | } |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 838 | |
| 839 | /*********************************************************************** |
| 840 | * DllCanUnloadNow (ATL.@) |
| 841 | */ |
Alexandre Julliard | d37f0ab | 2005-08-08 17:35:28 +0000 | [diff] [blame] | 842 | HRESULT WINAPI DllCanUnloadNow(void) |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 843 | { |
Michael Stefaniuc | 32f42f2 | 2006-10-06 23:02:28 +0200 | [diff] [blame] | 844 | TRACE("dll_count = %u\n", dll_count); |
Jacek Caban | 3475dcd | 2005-03-17 10:24:42 +0000 | [diff] [blame] | 845 | return dll_count ? S_FALSE : S_OK; |
| 846 | } |