[ATL]
[reactos.git] / reactos / dll / win32 / atl / registrar.c
index dd16aa0..70c1384 100644 (file)
@@ -27,7 +27,6 @@
 #include "winreg.h"
 #include "objbase.h"
 #include "oaidl.h"
-#include "string.h"
 
 #define ATL_INITGUID
 #include "atliface.h"
@@ -171,7 +170,7 @@ static HRESULT do_preprocess(const Registrar *This, LPCOLESTR data, strbuf *buf)
         }else {
             for(rep_iter = This->rep; rep_iter; rep_iter = rep_iter->next) {
                 if(rep_iter->key_len == iter-iter2
-                        && !memicmp(iter2, rep_iter->key, rep_iter->key_len))
+                        && !memicmpW(iter2, rep_iter->key, rep_iter->key_len))
                     break;
             }
             if(!rep_iter) {
@@ -243,7 +242,7 @@ static HRESULT do_process_key(LPCOLESTR *pstr, HKEY parent_key, strbuf *buf, BOO
                 strbuf_write(buf->str, &name, -1);
             }else if(key_type == DO_DELETE) {
                 TRACE("Deleting %s\n", debugstr_w(buf->str));
-                lres = RegDeleteTreeW(parent_key, buf->str);
+                RegDeleteTreeW(parent_key, buf->str);
             }else {
                 if(key_type == FORCE_REMOVE)
                     RegDeleteTreeW(parent_key, buf->str);
@@ -440,12 +439,12 @@ static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName,
     if(hins) {
         src = FindResourceW(hins, szID, szType);
         if(src) {
-            regstra = (LPSTR)LoadResource(hins, src);
+            regstra = LoadResource(hins, src);
             reslen = SizeofResource(hins, src);
             if(regstra) {
                 len = MultiByteToWideChar(CP_ACP, 0, regstra, reslen, NULL, 0)+1;
                 regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
-                MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, -1);
+                MultiByteToWideChar(CP_ACP, 0, regstra, reslen, regstrw, len);
                 regstrw[len-1] = '\0';
 
                 hres = string_register(This, regstrw, do_register);
@@ -455,7 +454,6 @@ static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName,
                 WARN("could not load resource\n");
                 hres = HRESULT_FROM_WIN32(GetLastError());
             }
-            HeapFree(GetProcessHeap(), 0, regstra);
         }else {
             WARN("Could not find source\n");
             hres = HRESULT_FROM_WIN32(GetLastError());
@@ -486,7 +484,7 @@ static HRESULT file_register(Registrar *This, LPCOLESTR fileName, BOOL do_regist
         if(lres == ERROR_SUCCESS) {
             len = MultiByteToWideChar(CP_ACP, 0, regstra, filelen, NULL, 0)+1;
             regstrw = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
-            MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, -1);
+            MultiByteToWideChar(CP_ACP, 0, regstra, filelen, regstrw, len);
             regstrw[len-1] = '\0';
             
             hres = string_register(This, regstrw, do_register);
@@ -760,39 +758,44 @@ static HRESULT do_register_dll_server(IRegistrar *pRegistrar, LPCOLESTR wszDll,
                                       LPCOLESTR wszId, BOOL do_register,
                                       const struct _ATL_REGMAP_ENTRY* pMapEntries)
 {
-    WCHAR buf[MAX_PATH];
+    IRegistrar *registrar;
     HRESULT hres;
     const struct _ATL_REGMAP_ENTRY *pMapEntry;
 
     static const WCHAR wszModule[] = {'M','O','D','U','L','E',0};
     static const WCHAR wszRegistry[] = {'R','E','G','I','S','T','R','Y',0};
-    static const WCHAR wszCLSID_ATLRegistrar[] =
-            {'C','L','S','I','D','_','A','T','L','R','e','g','i','s','t','r','a','r',0};
 
-    if (!pRegistrar)
-        Registrar_create(NULL, &IID_IRegistrar, (void**)&pRegistrar);
+    if (pRegistrar)
+        registrar = pRegistrar;
+    else
+        Registrar_create(NULL, &IID_IRegistrar, (void**)&registrar);
 
-    IRegistrar_AddReplacement(pRegistrar, wszModule, wszDll);
+    IRegistrar_AddReplacement(registrar, wszModule, wszDll);
 
     for (pMapEntry = pMapEntries; pMapEntry && pMapEntry->szKey; pMapEntry++)
-        IRegistrar_AddReplacement(pRegistrar, pMapEntry->szKey, pMapEntry->szData);
-
-    StringFromGUID2(&CLSID_ATLRegistrar, buf, sizeof(buf)/sizeof(buf[0]));
-    IRegistrar_AddReplacement(pRegistrar, wszCLSID_ATLRegistrar, buf);
+        IRegistrar_AddReplacement(registrar, pMapEntry->szKey, pMapEntry->szData);
 
     if(do_register)
-        hres = IRegistrar_ResourceRegisterSz(pRegistrar, wszDll, wszId, wszRegistry);
+        hres = IRegistrar_ResourceRegisterSz(registrar, wszDll, wszId, wszRegistry);
     else
-        hres = IRegistrar_ResourceUnregisterSz(pRegistrar, wszDll, wszId, wszRegistry);
+        hres = IRegistrar_ResourceUnregisterSz(registrar, wszDll, wszId, wszRegistry);
 
-    IRegistrar_Release(pRegistrar);
+    if(registrar != pRegistrar)
+        IRegistrar_Release(registrar);
     return hres;
 }
 
 static HRESULT do_register_server(BOOL do_register)
 {
-    static const WCHAR wszDll[] = {'a','t','l','.','d','l','l',0};
-    return do_register_dll_server(NULL, wszDll, MAKEINTRESOURCEW(101), do_register, NULL);
+    static const WCHAR CLSID_ATLRegistrarW[] =
+            {'C','L','S','I','D','_','A','T','L','R','e','g','i','s','t','r','a','r',0};
+    static const WCHAR atl_dllW[] = {'a','t','l','.','d','l','l',0};
+
+    WCHAR clsid_str[40];
+    const struct _ATL_REGMAP_ENTRY reg_map[] = {{CLSID_ATLRegistrarW, clsid_str}, {NULL,NULL}};
+
+    StringFromGUID2(&CLSID_ATLRegistrar, clsid_str, sizeof(clsid_str)/sizeof(WCHAR));
+    return do_register_dll_server(NULL, atl_dllW, MAKEINTRESOURCEW(101), do_register, reg_map);
 }
 
 /***********************************************************************