Implementation of File[Un]Register and Resource[Un]RegisterSz

Jacek Caban jack at itma.pwr.wroc.pl
Fri Mar 18 10:42:42 CST 2005


Changelog:
    Added implementation of File[Un]Register and Resource[Un]RegisterSz
-------------- next part --------------
Index: dlls/atl/registrar.c
===================================================================
RCS file: /home/wine/wine/dlls/atl/registrar.c,v
retrieving revision 1.4
diff -u -p -r1.4 registrar.c
--- dlls/atl/registrar.c	18 Mar 2005 10:25:29 -0000	1.4
+++ dlls/atl/registrar.c	18 Mar 2005 15:16:36 -0000
@@ -422,7 +422,7 @@ static HRESULT string_register(Registrar
 }
 
 static HRESULT resource_register(Registrar *This, LPCOLESTR resFileName,
-                        UINT nID, LPCOLESTR szType, BOOL do_register)
+                        LPCOLESTR szID, LPCOLESTR szType, BOOL do_register)
 {
     HINSTANCE hins;
     HRSRC src;
@@ -433,7 +433,7 @@ static HRESULT resource_register(Registr
 
     hins = LoadLibraryExW(resFileName, NULL, LOAD_LIBRARY_AS_DATAFILE);
     if(hins) {
-        src = FindResourceW(hins, (LPWSTR)nID, szType);
+        src = FindResourceW(hins, szID, szType);
         if(src) {
             regstra = (LPSTR)LoadResource(hins, src);
             reslen = SizeofResource(hins, src);
@@ -446,11 +446,11 @@ static HRESULT resource_register(Registr
                 hres = string_register(This, regstrw, do_register);
 
                 HeapFree(GetProcessHeap(), 0, regstrw);
-                HeapFree(GetProcessHeap(), 0, regstra);
             }else {
                 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());
@@ -464,6 +464,43 @@ static HRESULT resource_register(Registr
     return hres;
 }
 
+static HRESULT file_register(Registrar *This, LPCOLESTR fileName, BOOL do_register)
+{
+    HANDLE file;
+    DWORD filelen, len;
+    LPWSTR regstrw;
+    LPSTR regstra;
+    LRESULT lres;
+    HRESULT hres;
+
+    file = CreateFileW(fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY, NULL);
+    if(file) {
+        filelen = GetFileSize(file, NULL);
+        regstra = HeapAlloc(GetProcessHeap(), 0, filelen);
+        lres = ReadFile(file, regstra, filelen, NULL, NULL);
+        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);
+            regstrw[len-1] = '\0';
+            
+            hres = string_register(This, regstrw, do_register);
+
+            HeapFree(GetProcessHeap(), 0, regstrw);
+        }else {
+            WARN("Failed to read faile\n");
+            hres = HRESULT_FROM_WIN32(lres);
+        }
+        HeapFree(GetProcessHeap(), 0, regstra);
+        CloseHandle(file);
+    }else {
+        WARN("Could not open file\n");
+        hres = HRESULT_FROM_WIN32(GetLastError());
+    }
+
+    return hres;
+}
+
 static HRESULT WINAPI Registrar_QueryInterface(IRegistrar *iface, REFIID riid, void **ppvObject)
 {
     TRACE("(%p)->(%s %p\n", iface, debugstr_guid(riid), ppvObject);
@@ -549,30 +586,30 @@ static HRESULT WINAPI Registrar_Resource
                 LPCOLESTR szID, LPCOLESTR szType)
 {
     Registrar *This = (Registrar*)iface;
-    FIXME("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
-    return E_NOTIMPL;
+    TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
+    return resource_register(This, resFileName, szID, szType, TRUE);
 }
 
 static HRESULT WINAPI Registrar_ResourceUnregisterSz(IRegistrar* iface, LPCOLESTR resFileName,
                 LPCOLESTR szID, LPCOLESTR szType)
 {
     Registrar *This = (Registrar*)iface;
-    FIXME("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
-    return E_NOTIMPL;
+    TRACE("(%p)->(%s %s %s)\n", This, debugstr_w(resFileName), debugstr_w(szID), debugstr_w(szType));
+    return resource_register(This, resFileName, szID, szType, FALSE);
 }
 
 static HRESULT WINAPI Registrar_FileRegister(IRegistrar* iface, LPCOLESTR fileName)
 {
     Registrar *This = (Registrar*)iface;
-    FIXME("(%p)->(%s)\n", This, debugstr_w(fileName));
-    return E_NOTIMPL;
+    TRACE("(%p)->(%s)\n", This, debugstr_w(fileName));
+    return file_register(This, fileName, TRUE);
 }
 
 static HRESULT WINAPI Registrar_FileUnregister(IRegistrar* iface, LPCOLESTR fileName)
 {
     Registrar *This = (Registrar*)iface;
     FIXME("(%p)->(%s)\n", This, debugstr_w(fileName));
-    return E_NOTIMPL;
+    return file_register(This, fileName, FALSE);
 }
 
 static HRESULT WINAPI Registrar_StringRegister(IRegistrar* iface, LPCOLESTR data)
@@ -594,7 +631,7 @@ static HRESULT WINAPI Registrar_Resource
 {
     Registrar *This = (Registrar*)iface;
     TRACE("(%p)->(%s %d %s)\n", iface, debugstr_w(resFileName), nID, debugstr_w(szType));
-    return resource_register(This, resFileName, nID, szType, TRUE);
+    return resource_register(This, resFileName, (LPOLESTR)nID, szType, TRUE);
 }
 
 static HRESULT WINAPI Registrar_ResourceUnregister(IRegistrar* iface, LPCOLESTR resFileName,
@@ -602,7 +639,7 @@ static HRESULT WINAPI Registrar_Resource
 {
     Registrar *This = (Registrar*)iface;
     TRACE("(%p)->(%s %d %s)\n", This, debugstr_w(resFileName), nID, debugstr_w(szType));
-    return resource_register(This, resFileName, nID, szType, FALSE);
+    return resource_register(This, resFileName, (LPOLESTR)nID, szType, FALSE);
 }
 
 static IRegistrarVtbl RegistrarVtbl = {


More information about the wine-patches mailing list