[OLE32]
authorAmine Khaldi <amine.khaldi@reactos.org>
Wed, 12 Dec 2012 21:01:41 +0000 (21:01 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Wed, 12 Dec 2012 21:01:41 +0000 (21:01 +0000)
* Sync with Wine 1.5.19.

svn path=/trunk/; revision=57895

40 files changed:
reactos/dll/win32/ole32/CMakeLists.txt
reactos/dll/win32/ole32/antimoniker.c
reactos/dll/win32/ole32/classmoniker.c
reactos/dll/win32/ole32/clipboard.c
reactos/dll/win32/ole32/comcat.c
reactos/dll/win32/ole32/compobj.c
reactos/dll/win32/ole32/compobj_private.h
reactos/dll/win32/ole32/compositemoniker.c
reactos/dll/win32/ole32/datacache.c
reactos/dll/win32/ole32/dcom.idl
reactos/dll/win32/ole32/defaulthandler.c
reactos/dll/win32/ole32/errorinfo.c
reactos/dll/win32/ole32/filelockbytes.c
reactos/dll/win32/ole32/filemoniker.c
reactos/dll/win32/ole32/ftmarshal.c
reactos/dll/win32/ole32/ifs.c
reactos/dll/win32/ole32/itemmoniker.c
reactos/dll/win32/ole32/marshal.c
reactos/dll/win32/ole32/memlockbytes.c
reactos/dll/win32/ole32/moniker.c
reactos/dll/win32/ole32/msvc-thiscall.c [new file with mode: 0644]
reactos/dll/win32/ole32/msvc.h [new file with mode: 0644]
reactos/dll/win32/ole32/ole2.c
reactos/dll/win32/ole32/ole2impl.c
reactos/dll/win32/ole32/ole2stubs.c
reactos/dll/win32/ole32/ole32.spec
reactos/dll/win32/ole32/ole32_objidl.idl
reactos/dll/win32/ole32/ole32_oleidl.idl
reactos/dll/win32/ole32/ole32_unknwn.idl
reactos/dll/win32/ole32/oleobj.c
reactos/dll/win32/ole32/pointermoniker.c
reactos/dll/win32/ole32/rpc.c
reactos/dll/win32/ole32/stg_prop.c
reactos/dll/win32/ole32/stg_stream.c
reactos/dll/win32/ole32/storage32.c
reactos/dll/win32/ole32/storage32.h
reactos/dll/win32/ole32/stubmanager.c
reactos/dll/win32/ole32/usrmarshal.c
reactos/include/psdk/propidl.idl
reactos/media/doc/README.WINE

index e4122e7..c93031c 100644 (file)
@@ -9,10 +9,10 @@ add_definitions(-D_WIN32_WINNT=0x600)
 add_definitions(
     -D__WINESRC__
     -D_OLE32_
+    -DCOM_NO_WINDOWS_H
     -DENTRY_PREFIX=OLE32_
     -DPROXY_CLSID=CLSID_PSFactoryBuffer
-    -DWINE_REGISTER_DLL
-    -DCOM_NO_WINDOWS_H)
+    -DWINE_REGISTER_DLL)
 
 include_directories(${REACTOS_SOURCE_DIR}/include/reactos/wine)
 
@@ -71,9 +71,17 @@ list(APPEND SOURCE
     ${CMAKE_CURRENT_BINARY_DIR}/proxy.dlldata.c
     ${CMAKE_CURRENT_BINARY_DIR}/ole32.def)
 
+if(MSVC)
+    if(ARCH STREQUAL "i386")
+        list(APPEND SOURCE msvc-thiscall.c)
+    endif()
+    set_source_files_properties(stg_prop.c PROPERTIES COMPILE_FLAGS "/FImsvc.h")
+endif()
+
 add_library(ole32 SHARED ${SOURCE})
 set_module_type(ole32 win32dll)
 target_link_libraries(ole32 wine uuid ${PSEH_LIB})
 add_importlibs(ole32 advapi32 user32 gdi32 rpcrt4 msvcrt kernel32 ntdll)
+add_delay_importlibs(ole32 oleaut32)
 add_dependencies(ole32 ole32idl)
 add_cd_file(TARGET ole32 DESTINATION reactos/system32 FOR all)
index 9f1958b..4c71fd4 100644 (file)
@@ -629,14 +629,13 @@ HRESULT WINAPI CreateAntiMoniker(IMoniker **ppmk)
             (void**)ppmk);
 }
 
-static HRESULT WINAPI AntiMonikerCF_QueryInterface(LPCLASSFACTORY iface,
-                                                  REFIID riid, LPVOID *ppv)
+static HRESULT WINAPI AntiMonikerCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index d220d91..d5c013b 100644 (file)
@@ -816,14 +816,13 @@ HRESULT ClassMoniker_CreateFromDisplayName(LPBC pbc, LPCOLESTR szDisplayName, LP
     return hr;
 }
 
-static HRESULT WINAPI ClassMonikerCF_QueryInterface(LPCLASSFACTORY iface,
-                                                  REFIID riid, LPVOID *ppv)
+static HRESULT WINAPI ClassMonikerCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index b98404f..a7308c2 100644 (file)
@@ -662,8 +662,9 @@ static HRESULT render_embed_source_hack(IDataObject *data, LPFORMATETC fmt)
             ProgIDFromCLSID(&clsID, &strProgID);
 
             WideCharToMultiByte( CP_ACP, 0, strProgID, -1, strOleTypeName, sizeof(strOleTypeName), NULL, NULL );
-            OLECONVERT_CreateOleStream(std.u.pstg);
+            STORAGE_CreateOleStream(std.u.pstg, 0);
             OLECONVERT_CreateCompObjStream(std.u.pstg, strOleTypeName);
+            CoTaskMemFree(strProgID);
         }
     }
 
index b10075b..2882890 100644 (file)
@@ -31,6 +31,8 @@
 
 #include "ole2.h"
 #include "comcat.h"
+#include "compobj_private.h"
+
 #include "wine/unicode.h"
 #include "wine/debug.h"
 
@@ -93,17 +95,14 @@ static HRESULT COMCAT_RegisterClassCategories(
     if (FAILED(res)) return res;
 
     /* Create (or open) the CLSID key. */
-    res = RegCreateKeyExW(HKEY_CLASSES_ROOT, clsid_keyname, 0, NULL, 0,
-                         KEY_READ | KEY_WRITE, NULL, &clsid_key, NULL);
+    res = create_classes_key(HKEY_CLASSES_ROOT, clsid_keyname, KEY_READ|KEY_WRITE, &clsid_key);
     if (res != ERROR_SUCCESS) return E_FAIL;
 
     /* Create (or open) the class key. */
-    res = RegCreateKeyExW(clsid_key, keyname, 0, NULL, 0,
-                         KEY_READ | KEY_WRITE, NULL, &class_key, NULL);
+    res = create_classes_key(clsid_key, keyname, KEY_READ|KEY_WRITE, &class_key);
     if (res == ERROR_SUCCESS) {
        /* Create (or open) the category type key. */
-       res = RegCreateKeyExW(class_key, type, 0, NULL, 0,
-                             KEY_READ | KEY_WRITE, NULL, &type_key, NULL);
+       res = create_classes_key(class_key, type, KEY_READ|KEY_WRITE, &type_key);
        if (res == ERROR_SUCCESS) {
            for (; cCategories; --cCategories, ++rgcatid) {
                HKEY key;
@@ -113,8 +112,7 @@ static HRESULT COMCAT_RegisterClassCategories(
                if (FAILED(res)) continue;
 
                /* Do the register. */
-               res = RegCreateKeyExW(type_key, keyname, 0, NULL, 0,
-                                     KEY_READ | KEY_WRITE, NULL, &key, NULL);
+               res = create_classes_key(type_key, keyname, KEY_READ|KEY_WRITE, &key);
                if (res == ERROR_SUCCESS) RegCloseKey(key);
            }
            res = S_OK;
@@ -148,8 +146,7 @@ static HRESULT COMCAT_UnRegisterClassCategories(
     lstrcpyW(keyname + 45, type);
 
     /* Open the class category type key. */
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0,
-                       KEY_READ | KEY_WRITE, &type_key);
+    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ|KEY_WRITE, &type_key);
     if (res != ERROR_SUCCESS) return E_FAIL;
 
     for (; cCategories; --cCategories, ++rgcatid) {
@@ -237,11 +234,11 @@ static HRESULT COMCAT_IsClassOfCategories(
 
     /* Check that every given category is implemented by class. */
     if (*categories->impl_strings) {
-       res = RegOpenKeyExW(key, impl_keyname, 0, KEY_READ, &subkey);
+       res = open_classes_key(key, impl_keyname, KEY_READ, &subkey);
        if (res != ERROR_SUCCESS) return S_FALSE;
        for (string = categories->impl_strings; *string; string += 39) {
            HKEY catkey;
-           res = RegOpenKeyExW(subkey, string, 0, 0, &catkey);
+           res = open_classes_key(subkey, string, 0, &catkey);
            if (res != ERROR_SUCCESS) {
                RegCloseKey(subkey);
                return S_FALSE;
@@ -252,7 +249,7 @@ static HRESULT COMCAT_IsClassOfCategories(
     }
 
     /* Check that all categories required by class are given. */
-    res = RegOpenKeyExW(key, req_keyname, 0, KEY_READ, &subkey);
+    res = open_classes_key(key, req_keyname, KEY_READ, &subkey);
     if (res == ERROR_SUCCESS) {
        for (index = 0; ; ++index) {
            WCHAR keyname[39];
@@ -335,8 +332,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
        return E_POINTER;
 
     /* Create (or open) the component categories key. */
-    res = RegCreateKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0, NULL, 0,
-                         KEY_READ | KEY_WRITE, NULL, &comcat_key, NULL);
+    res = create_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
     if (res != ERROR_SUCCESS) return E_FAIL;
 
     for (; cCategories; --cCategories, ++rgci) {
@@ -347,8 +343,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_RegisterCategories(
 
        /* Create (or open) the key for this category. */
        if (!StringFromGUID2(&rgci->catid, keyname, 39)) continue;
-       res = RegCreateKeyExW(comcat_key, keyname, 0, NULL, 0,
-                             KEY_READ | KEY_WRITE, NULL, &cat_key, NULL);
+       res = create_classes_key(comcat_key, keyname, KEY_READ|KEY_WRITE, &cat_key);
        if (res != ERROR_SUCCESS) continue;
 
        /* Set the value for this locale's description. */
@@ -381,8 +376,7 @@ static HRESULT WINAPI COMCAT_ICatRegister_UnRegisterCategories(
        return E_POINTER;
 
     /* Open the component categories key. */
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, comcat_keyname, 0,
-                       KEY_READ | KEY_WRITE, &comcat_key);
+    res = open_classes_key(HKEY_CLASSES_ROOT, comcat_keyname, KEY_READ|KEY_WRITE, &comcat_key);
     if (res != ERROR_SUCCESS) return E_FAIL;
 
     for (; cCategories; --cCategories, ++rgcatid) {
@@ -523,7 +517,7 @@ static HRESULT WINAPI COMCAT_ICatInformation_GetCategoryDesc(
 
     /* Open the key for this category. */
     if (!StringFromGUID2(rcatid, keyname + 21, 39)) return E_FAIL;
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
+    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
     if (res != ERROR_SUCCESS) return CAT_E_CATIDNOEXIST;
 
     /* Allocate a sensible amount of memory for the description. */
@@ -616,7 +610,7 @@ static HRESULT WINAPI COMCAT_ICatInformation_IsClassOfCategories(
                                               cRequired, rgcatidReq);
     if (categories == NULL) return E_OUTOFMEMORY;
 
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &key);
+    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &key);
     if (res == ERROR_SUCCESS) {
        res = COMCAT_IsClassOfCategories(key, categories);
        RegCloseKey(key);
@@ -720,7 +714,7 @@ static HRESULT WINAPI COMCAT_IClassFactory_QueryInterface(
        IsEqualGUID(riid, &IID_IClassFactory))
     {
         *ppvObj = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
        return S_OK;
     }
 
@@ -891,7 +885,7 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Next(
        hr = CLSIDFromString(catid, &rgelt->catid);
        if (FAILED(hr)) continue;
 
-       res = RegOpenKeyExW(This->key, catid, 0, KEY_READ, &subkey);
+       res = open_classes_key(This->key, catid, KEY_READ, &subkey);
        if (res != ERROR_SUCCESS) continue;
 
        hr = COMCAT_GetCategoryDesc(subkey, This->lcid,
@@ -952,7 +946,7 @@ static HRESULT WINAPI COMCAT_IEnumCATEGORYINFO_Clone(
     new_this->ref = 1;
     new_this->lcid = This->lcid;
     /* FIXME: could we more efficiently use DuplicateHandle? */
-    RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
+    open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
     new_this->next_index = This->next_index;
 
     *ppenum = &new_this->IEnumCATEGORYINFO_iface;
@@ -982,7 +976,7 @@ static IEnumCATEGORYINFO *COMCAT_IEnumCATEGORYINFO_Construct(LCID lcid)
 
         This->IEnumCATEGORYINFO_iface.lpVtbl = &COMCAT_IEnumCATEGORYINFO_Vtbl;
        This->lcid = lcid;
-       RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
+       open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
     }
     return &This->IEnumCATEGORYINFO_iface;
 }
@@ -1075,7 +1069,7 @@ static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Next(
        hr = CLSIDFromString(clsid, rgelt);
        if (FAILED(hr)) continue;
 
-       res = RegOpenKeyExW(This->key, clsid, 0, KEY_READ, &subkey);
+       res = open_classes_key(This->key, clsid, KEY_READ, &subkey);
        if (res != ERROR_SUCCESS) continue;
 
        hr = COMCAT_IsClassOfCategories(subkey, This->categories);
@@ -1140,7 +1134,7 @@ static HRESULT WINAPI COMCAT_CLSID_IEnumGUID_Clone(
     }
     memcpy(new_this->categories, This->categories, size);
     /* FIXME: could we more efficiently use DuplicateHandle? */
-    RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &new_this->key);
+    open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &new_this->key);
     new_this->next_index = This->next_index;
 
     *ppenum = (LPENUMGUID)new_this;
@@ -1168,7 +1162,7 @@ static LPENUMGUID COMCAT_CLSID_IEnumGUID_Construct(struct class_categories *cate
 
        This->lpVtbl = &COMCAT_CLSID_IEnumGUID_Vtbl;
        This->categories = categories;
-       RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, KEY_READ, &This->key);
+       open_classes_key(HKEY_CLASSES_ROOT, keyname, KEY_READ, &This->key);
     }
     return (LPENUMGUID)This;
 }
@@ -1308,7 +1302,7 @@ static HRESULT WINAPI COMCAT_CATID_IEnumGUID_Clone(
     new_this->ref = 1;
     lstrcpyW(new_this->keyname, This->keyname);
     /* FIXME: could we more efficiently use DuplicateHandle? */
-    RegOpenKeyExW(HKEY_CLASSES_ROOT, new_this->keyname, 0, KEY_READ, &new_this->key);
+    open_classes_key(HKEY_CLASSES_ROOT, new_this->keyname, KEY_READ, &new_this->key);
     new_this->next_index = This->next_index;
 
     *ppenum = (LPENUMGUID)new_this;
@@ -1339,7 +1333,7 @@ static LPENUMGUID COMCAT_CATID_IEnumGUID_Construct(
        memcpy(This->keyname, prefix, sizeof(prefix));
        StringFromGUID2(rclsid, This->keyname + 6, 39);
        lstrcpyW(This->keyname + 44, postfix);
-       RegOpenKeyExW(HKEY_CLASSES_ROOT, This->keyname, 0, KEY_READ, &This->key);
+       open_classes_key(HKEY_CLASSES_ROOT, This->keyname, KEY_READ, &This->key);
     }
     return (LPENUMGUID)This;
 }
index 72ba32a..646a170 100644 (file)
@@ -47,6 +47,8 @@
 #define NONAMELESSUNION
 #define NONAMELESSSTRUCT
 
+#include "ntstatus.h"
+#define WIN32_NO_STATUS
 #include "windef.h"
 #include "winbase.h"
 #include "winerror.h"
@@ -135,6 +137,125 @@ static CRITICAL_SECTION_DEBUG class_cs_debug =
 };
 static CRITICAL_SECTION csRegisteredClassList = { &class_cs_debug, -1, 0, 0, 0, 0 };
 
+/* wrapper for NtCreateKey that creates the key recursively if necessary */
+static NTSTATUS create_key( HKEY *retkey, ACCESS_MASK access, OBJECT_ATTRIBUTES *attr )
+{
+    NTSTATUS status = NtCreateKey( (HANDLE *)retkey, access, attr, 0, NULL, 0, NULL );
+
+    if (status == STATUS_OBJECT_NAME_NOT_FOUND)
+    {
+        HANDLE subkey, root = attr->RootDirectory;
+        WCHAR *buffer = attr->ObjectName->Buffer;
+        DWORD attrs, pos = 0, i = 0, len = attr->ObjectName->Length / sizeof(WCHAR);
+        UNICODE_STRING str;
+
+        while (i < len && buffer[i] != '\\') i++;
+        if (i == len) return status;
+
+        attrs = attr->Attributes;
+        attr->ObjectName = &str;
+
+        while (i < len)
+        {
+            str.Buffer = buffer + pos;
+            str.Length = (i - pos) * sizeof(WCHAR);
+            status = NtCreateKey( &subkey, access, attr, 0, NULL, 0, NULL );
+            if (attr->RootDirectory != root) NtClose( attr->RootDirectory );
+            if (status) return status;
+            attr->RootDirectory = subkey;
+            while (i < len && buffer[i] == '\\') i++;
+            pos = i;
+            while (i < len && buffer[i] != '\\') i++;
+        }
+        str.Buffer = buffer + pos;
+        str.Length = (i - pos) * sizeof(WCHAR);
+        attr->Attributes = attrs;
+        status = NtCreateKey( (PHANDLE)retkey, access, attr, 0, NULL, 0, NULL );
+        if (attr->RootDirectory != root) NtClose( attr->RootDirectory );
+    }
+    return status;
+}
+
+#ifdef __REACTOS__
+static const WCHAR classes_rootW[] = L"\\REGISTRY\\Machine\\Software\\Classes";
+#else
+static const WCHAR classes_rootW[] =
+    {'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\','C','l','a','s','s','e','s',0};
+#endif
+
+static HKEY classes_root_hkey;
+
+/* create the special HKEY_CLASSES_ROOT key */
+static HKEY create_classes_root_hkey(void)
+{
+    HKEY hkey, ret = 0;
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING name;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = 0;
+    attr.ObjectName = &name;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+    RtlInitUnicodeString( &name, classes_rootW );
+    if (create_key( &hkey, MAXIMUM_ALLOWED, &attr )) return 0;
+    TRACE( "%s -> %p\n", debugstr_w(attr.ObjectName->Buffer), hkey );
+
+    if (!(ret = InterlockedCompareExchangePointer( (void **)&classes_root_hkey, hkey, 0 )))
+        ret = hkey;
+    else
+        NtClose( hkey );  /* somebody beat us to it */
+    return ret;
+}
+
+/* map the hkey from special root to normal key if necessary */
+static inline HKEY get_classes_root_hkey( HKEY hkey )
+{
+    HKEY ret = hkey;
+
+    if (hkey == HKEY_CLASSES_ROOT && !(ret = classes_root_hkey))
+        ret = create_classes_root_hkey();
+
+    return ret;
+}
+
+LSTATUS create_classes_key( HKEY hkey, const WCHAR *name, REGSAM access, HKEY *retkey )
+{
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW;
+
+    if (!(hkey = get_classes_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = hkey;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+    RtlInitUnicodeString( &nameW, name );
+
+    return RtlNtStatusToDosError( create_key( retkey, access, &attr ) );
+}
+
+LSTATUS open_classes_key( HKEY hkey, const WCHAR *name, REGSAM access, HKEY *retkey )
+{
+    OBJECT_ATTRIBUTES attr;
+    UNICODE_STRING nameW;
+
+    if (!(hkey = get_classes_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
+
+    attr.Length = sizeof(attr);
+    attr.RootDirectory = hkey;
+    attr.ObjectName = &nameW;
+    attr.Attributes = 0;
+    attr.SecurityDescriptor = NULL;
+    attr.SecurityQualityOfService = NULL;
+    RtlInitUnicodeString( &nameW, name );
+
+    return RtlNtStatusToDosError( NtOpenKey( (HANDLE *)retkey, access, &attr ) );
+}
+
 /*****************************************************************************
  * This section contains OpenDllList definitions
  *
@@ -464,7 +585,8 @@ static void COM_RevokeAllClasses(const struct apartment *apt)
  */
 
 typedef struct ManualResetEvent {
-    ISynchronize   ISynchronize_iface;
+    ISynchronize        ISynchronize_iface;
+    ISynchronizeHandle  ISynchronizeHandle_iface;
     LONG ref;
     HANDLE event;
 } MREImpl;
@@ -477,22 +599,21 @@ static inline MREImpl *impl_from_ISynchronize(ISynchronize *iface)
 static HRESULT WINAPI ISynchronize_fnQueryInterface(ISynchronize *iface, REFIID riid, void **ppv)
 {
     MREImpl *This = impl_from_ISynchronize(iface);
+
     TRACE("%p (%s, %p)\n", This, debugstr_guid(riid), ppv);
 
-    *ppv = NULL;
-    if(IsEqualGUID(riid, &IID_IUnknown) ||
-       IsEqualGUID(riid, &IID_ISynchronize))
-        *ppv = This;
-    else
+    if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ISynchronize)) {
+        *ppv = &This->ISynchronize_iface;
+    }else if(IsEqualGUID(riid, &IID_ISynchronizeHandle)) {
+        *ppv = &This->ISynchronizeHandle_iface;
+    }else {
         ERR("Unknown interface %s requested.\n", debugstr_guid(riid));
-
-    if(*ppv)
-    {
-        IUnknown_AddRef((IUnknown*)*ppv);
-        return S_OK;
+        *ppv = NULL;
+        return E_NOINTERFACE;
     }
 
-    return E_NOINTERFACE;
+    IUnknown_AddRef((IUnknown*)*ppv);
+    return S_OK;
 }
 
 static ULONG WINAPI ISynchronize_fnAddRef(ISynchronize *iface)
@@ -552,6 +673,44 @@ static ISynchronizeVtbl vt_ISynchronize = {
     ISynchronize_fnReset
 };
 
+static inline MREImpl *impl_from_ISynchronizeHandle(ISynchronizeHandle *iface)
+{
+    return CONTAINING_RECORD(iface, MREImpl, ISynchronizeHandle_iface);
+}
+
+static HRESULT WINAPI SynchronizeHandle_QueryInterface(ISynchronizeHandle *iface, REFIID riid, void **ppv)
+{
+    MREImpl *This = impl_from_ISynchronizeHandle(iface);
+    return ISynchronize_QueryInterface(&This->ISynchronize_iface, riid, ppv);
+}
+
+static ULONG WINAPI SynchronizeHandle_AddRef(ISynchronizeHandle *iface)
+{
+    MREImpl *This = impl_from_ISynchronizeHandle(iface);
+    return ISynchronize_AddRef(&This->ISynchronize_iface);
+}
+
+static ULONG WINAPI SynchronizeHandle_Release(ISynchronizeHandle *iface)
+{
+    MREImpl *This = impl_from_ISynchronizeHandle(iface);
+    return ISynchronize_Release(&This->ISynchronize_iface);
+}
+
+static HRESULT WINAPI SynchronizeHandle_GetHandle(ISynchronizeHandle *iface, HANDLE *ph)
+{
+    MREImpl *This = impl_from_ISynchronizeHandle(iface);
+
+    *ph = This->event;
+    return S_OK;
+}
+
+static const ISynchronizeHandleVtbl SynchronizeHandleVtbl = {
+    SynchronizeHandle_QueryInterface,
+    SynchronizeHandle_AddRef,
+    SynchronizeHandle_Release,
+    SynchronizeHandle_GetHandle
+};
+
 static HRESULT ManualResetEvent_Construct(IUnknown *punkouter, REFIID iid, void **ppv)
 {
     MREImpl *This = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(MREImpl));
@@ -562,6 +721,7 @@ static HRESULT ManualResetEvent_Construct(IUnknown *punkouter, REFIID iid, void
 
     This->ref = 1;
     This->ISynchronize_iface.lpVtbl = &vt_ISynchronize;
+    This->ISynchronizeHandle_iface.lpVtbl = &SynchronizeHandleVtbl;
     This->event = CreateEventW(NULL, TRUE, FALSE, NULL);
 
     hr = ISynchronize_QueryInterface(&This->ISynchronize_iface, iid, ppv);
@@ -732,7 +892,7 @@ DWORD apartment_release(struct apartment *apt)
          * apartment, which it must do. */
         assert(list_empty(&apt->stubmgrs));
 
-        if (apt->filter) IUnknown_Release(apt->filter);
+        if (apt->filter) IMessageFilter_Release(apt->filter);
 
         /* free as many unused libraries as possible... */
         apartment_freeunusedlibraries(apt, 0);
@@ -928,16 +1088,14 @@ static HRESULT apartment_getclassobject(struct apartment *apt, LPCWSTR dllpath,
  *
  *     Reads a registry value and expands it when necessary
  */
-static DWORD COM_RegReadPath(HKEY hkeyroot, const WCHAR *keyname, const WCHAR *valuename, WCHAR * dst, DWORD dstlen)
+static DWORD COM_RegReadPath(HKEY hkeyroot, WCHAR * dst, DWORD dstlen)
 {
        DWORD ret;
-       HKEY key;
        DWORD keytype;
        WCHAR src[MAX_PATH];
        DWORD dwLength = dstlen * sizeof(WCHAR);
 
-       if((ret = RegOpenKeyExW(hkeyroot, keyname, 0, KEY_READ, &key)) == ERROR_SUCCESS) {
-          if( (ret = RegQueryValueExW(key, NULL, NULL, &keytype, (LPBYTE)src, &dwLength)) == ERROR_SUCCESS ) {
+        if( (ret = RegQueryValueExW(hkeyroot, NULL, NULL, &keytype, (LPBYTE)src, &dwLength)) == ERROR_SUCCESS ) {
             if (keytype == REG_EXPAND_SZ) {
               if (dstlen <= ExpandEnvironmentStringsW(src, dst, dstlen)) ret = ERROR_MORE_DATA;
             } else {
@@ -953,9 +1111,7 @@ static DWORD COM_RegReadPath(HKEY hkeyroot, const WCHAR *keyname, const WCHAR *v
               }
               lstrcpynW(dst, src, dstlen);
             }
-         }
-          RegCloseKey (key);
-       }
+        }
        return ret;
 }
 
@@ -980,7 +1136,7 @@ static HRESULT apartment_hostobject(struct apartment *apt,
 
     TRACE("clsid %s, iid %s\n", debugstr_guid(&params->clsid), debugstr_guid(&params->iid));
 
-    if (COM_RegReadPath(params->hkeydll, NULL, NULL, dllpath, ARRAYSIZE(dllpath)) != ERROR_SUCCESS)
+    if (COM_RegReadPath(params->hkeydll, dllpath, ARRAYSIZE(dllpath)) != ERROR_SUCCESS)
     {
         /* failure: CLSID is not found in registry */
         WARN("class %s not registered inproc\n", debugstr_guid(&params->clsid));
@@ -1254,7 +1410,7 @@ static void COM_TlsDestroy(void)
         if (info->apt) apartment_release(info->apt);
         if (info->errorinfo) IErrorInfo_Release(info->errorinfo);
         if (info->state) IUnknown_Release(info->state);
-        if (info->spy) IUnknown_Release(info->spy);
+        if (info->spy) IInitializeSpy_Release(info->spy);
         if (info->context_token) IObjContext_Release(info->context_token);
         HeapFree(GetProcessHeap(), 0, info);
         NtCurrentTeb()->ReservedForOle = NULL;
@@ -1313,7 +1469,7 @@ HRESULT WINAPI CoRegisterInitializeSpy(IInitializeSpy *spy, ULARGE_INTEGER *cook
         return E_UNEXPECTED;
     }
 
-    hr = IUnknown_QueryInterface(spy, &IID_IInitializeSpy, (void **) &info->spy);
+    hr = IInitializeSpy_QueryInterface(spy, &IID_IInitializeSpy, (void **) &info->spy);
     if (SUCCEEDED(hr))
     {
         cookie->QuadPart = (DWORD_PTR)spy;
@@ -1345,7 +1501,7 @@ HRESULT WINAPI CoRevokeInitializeSpy(ULARGE_INTEGER cookie)
     if (!info || !info->spy || cookie.QuadPart != (DWORD_PTR)info->spy)
         return E_INVALIDARG;
 
-    IUnknown_Release(info->spy);
+    IInitializeSpy_Release(info->spy);
     info->spy = NULL;
     return S_OK;
 }
@@ -1557,6 +1713,8 @@ HRESULT WINAPI CoDisconnectObject( LPUNKNOWN lpUnk, DWORD reserved )
 
     TRACE("(%p, 0x%08x)\n", lpUnk, reserved);
 
+    if (!lpUnk) return E_INVALIDARG;
+
     hr = IUnknown_QueryInterface(lpUnk, &IID_IMarshal, (void **)&marshal);
     if (hr == S_OK)
     {
@@ -1777,7 +1935,7 @@ HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY
 
     strcpyW(path, wszCLSIDSlash);
     StringFromGUID2(clsid, path + strlenW(wszCLSIDSlash), CHARS_IN_GUID);
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, keyname ? KEY_READ : access, &key);
+    res = open_classes_key(HKEY_CLASSES_ROOT, path, keyname ? KEY_READ : access, &key);
     if (res == ERROR_FILE_NOT_FOUND)
         return REGDB_E_CLASSNOTREG;
     else if (res != ERROR_SUCCESS)
@@ -1789,7 +1947,7 @@ HRESULT COM_OpenKeyForCLSID(REFCLSID clsid, LPCWSTR keyname, REGSAM access, HKEY
         return S_OK;
     }
 
-    res = RegOpenKeyExW(key, keyname, 0, access, subkey);
+    res = open_classes_key(key, keyname, access, subkey);
     RegCloseKey(key);
     if (res == ERROR_FILE_NOT_FOUND)
         return REGDB_E_KEYMISSING;
@@ -1827,7 +1985,7 @@ HRESULT COM_OpenKeyForAppIdFromCLSID(REFCLSID clsid, REGSAM access, HKEY *subkey
 
     strcpyW(keyname, szAppIdKey);
     strcatW(keyname, buf);
-    res = RegOpenKeyExW(HKEY_CLASSES_ROOT, keyname, 0, access, subkey);
+    res = open_classes_key(HKEY_CLASSES_ROOT, keyname, access, subkey);
     if (res == ERROR_FILE_NOT_FOUND)
         return REGDB_E_KEYMISSING;
     else if (res != ERROR_SUCCESS)
@@ -1920,7 +2078,7 @@ HRESULT WINAPI CLSIDFromProgID(LPCOLESTR progid, LPCLSID clsid)
     buf = HeapAlloc( GetProcessHeap(),0,(strlenW(progid)+8) * sizeof(WCHAR) );
     strcpyW( buf, progid );
     strcatW( buf, clsidW );
-    if (RegOpenKeyW(HKEY_CLASSES_ROOT,buf,&xhkey))
+    if (open_classes_key(HKEY_CLASSES_ROOT, buf, MAXIMUM_ALLOWED, &xhkey))
     {
         HeapFree(GetProcessHeap(),0,buf);
         WARN("couldn't open key for ProgID %s\n", debugstr_w(progid));
@@ -2018,7 +2176,7 @@ HRESULT WINAPI CoGetPSClsid(REFIID riid, CLSID *pclsid)
     strcpyW(path + ARRAYSIZE(wszInterface) - 1 + CHARS_IN_GUID - 1, wszPSC);
 
     /* Open the key.. */
-    if (RegOpenKeyExW(HKEY_CLASSES_ROOT, path, 0, KEY_READ, &hkey))
+    if (open_classes_key(HKEY_CLASSES_ROOT, path, KEY_READ, &hkey))
     {
         WARN("No PSFactoryBuffer object is registered for IID %s\n", debugstr_guid(riid));
         return REGDB_E_IIDNOTREG;
@@ -2342,7 +2500,7 @@ static HRESULT get_inproc_class_object(APARTMENT *apt, HKEY hkeydll,
     else
         apartment_threaded = !apt->multi_threaded;
 
-    if (COM_RegReadPath(hkeydll, NULL, NULL, dllpath, ARRAYSIZE(dllpath)) != ERROR_SUCCESS)
+    if (COM_RegReadPath(hkeydll, dllpath, ARRAYSIZE(dllpath)) != ERROR_SUCCESS)
     {
         /* failure: CLSID is not found in registry */
         WARN("class %s not registered inproc\n", debugstr_guid(rclsid));
@@ -3767,10 +3925,9 @@ HRESULT WINAPI CoWaitForMultipleHandles(DWORD dwFlags, DWORD dwTimeout,
         {
             TRACE("waiting for rpc completion\n");
 
-            res = WaitForMultipleObjectsEx(cHandles, pHandles,
-                (dwFlags & COWAIT_WAITALL) ? TRUE : FALSE,
+            res = WaitForMultipleObjectsEx(cHandles, pHandles, (dwFlags & COWAIT_WAITALL) != 0,
                 (dwTimeout == INFINITE) ? INFINITE : start_time + dwTimeout - now,
-                (dwFlags & COWAIT_ALERTABLE) ? TRUE : FALSE);
+                (dwFlags & COWAIT_ALERTABLE) != 0);
         }
 
         switch (res)
@@ -4239,6 +4396,15 @@ HRESULT WINAPI CoGetContextToken( ULONG_PTR *token )
     return S_OK;
 }
 
+/***********************************************************************
+ *           CoGetDefaultContext [OLE32.@]
+ */
+HRESULT WINAPI CoGetDefaultContext(APTTYPE type, REFIID riid, LPVOID *ppv)
+{
+    FIXME("%d %s %p stub\n", type, debugstr_guid(riid), ppv);
+    return E_NOINTERFACE;
+}
+
 HRESULT Handler_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
 {
     static const WCHAR wszInprocHandler32[] = {'I','n','p','r','o','c','H','a','n','d','l','e','r','3','2',0};
@@ -4250,7 +4416,7 @@ HRESULT Handler_DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
     {
         WCHAR dllpath[MAX_PATH+1];
 
-        if (COM_RegReadPath(hkey, NULL, NULL, dllpath, ARRAYSIZE(dllpath)) == ERROR_SUCCESS)
+        if (COM_RegReadPath(hkey, dllpath, ARRAYSIZE(dllpath)) == ERROR_SUCCESS)
         {
             static const WCHAR wszOle32[] = {'o','l','e','3','2','.','d','l','l',0};
             if (!strcmpiW(dllpath, wszOle32))
index fc92389..b76e3a7 100644 (file)
@@ -185,7 +185,8 @@ ULONG stub_manager_int_release(struct stub_manager *This) DECLSPEC_HIDDEN;
 struct stub_manager *new_stub_manager(APARTMENT *apt, IUnknown *object) DECLSPEC_HIDDEN;
 ULONG stub_manager_ext_addref(struct stub_manager *m, ULONG refs, BOOL tableweak) DECLSPEC_HIDDEN;
 ULONG stub_manager_ext_release(struct stub_manager *m, ULONG refs, BOOL tableweak, BOOL last_unlock_releases) DECLSPEC_HIDDEN;
-struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, MSHLFLAGS flags) DECLSPEC_HIDDEN;
+struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid,
+     DWORD dest_context, void *dest_context_data, MSHLFLAGS flags) DECLSPEC_HIDDEN;
 struct ifstub *stub_manager_find_ifstub(struct stub_manager *m, REFIID iid, MSHLFLAGS flags) DECLSPEC_HIDDEN;
 struct stub_manager *get_stub_manager(APARTMENT *apt, OID oid) DECLSPEC_HIDDEN;
 struct stub_manager *get_stub_manager_from_object(APARTMENT *apt, void *object) DECLSPEC_HIDDEN;
@@ -195,7 +196,7 @@ void stub_manager_release_marshal_data(struct stub_manager *m, ULONG refs, const
 HRESULT ipid_get_dispatch_params(const IPID *ipid, APARTMENT **stub_apt, IRpcStubBuffer **stub, IRpcChannelBuffer **chan, IID *iid, IUnknown **iface) DECLSPEC_HIDDEN;
 HRESULT start_apartment_remote_unknown(void) DECLSPEC_HIDDEN;
 
-HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, MSHLFLAGS mshlflags) DECLSPEC_HIDDEN;
+HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *obj, DWORD dest_context, void *dest_context_data, MSHLFLAGS mshlflags) DECLSPEC_HIDDEN;
 
 /* RPC Backend */
 
@@ -206,7 +207,7 @@ HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid,
                                 const OXID_INFO *oxid_info,
                                 DWORD dest_context, void *dest_context_data,
                                 IRpcChannelBuffer **chan) DECLSPEC_HIDDEN;
-HRESULT RPC_CreateServerChannel(IRpcChannelBuffer **chan) DECLSPEC_HIDDEN;
+HRESULT RPC_CreateServerChannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan) DECLSPEC_HIDDEN;
 void    RPC_ExecuteCall(struct dispatch_params *params) DECLSPEC_HIDDEN;
 HRESULT RPC_RegisterInterface(REFIID riid) DECLSPEC_HIDDEN;
 void    RPC_UnregisterInterface(REFIID riid) DECLSPEC_HIDDEN;
@@ -308,4 +309,7 @@ extern UINT object_descriptor_clipboard_format DECLSPEC_HIDDEN;
 extern UINT link_source_descriptor_clipboard_format DECLSPEC_HIDDEN;
 extern UINT ole_private_data_clipboard_format DECLSPEC_HIDDEN;
 
+extern LSTATUS create_classes_key(HKEY, const WCHAR *, REGSAM, HKEY *) DECLSPEC_HIDDEN;
+extern LSTATUS open_classes_key(HKEY, const WCHAR *, REGSAM, HKEY *) DECLSPEC_HIDDEN;
+
 #endif /* __WINE_OLE_COMPOBJ_H */
index f67e56c..a6cfd62 100644 (file)
@@ -1968,14 +1968,13 @@ MonikerCommonPrefixWith(IMoniker* pmkThis,IMoniker* pmkOther,IMoniker** ppmkComm
     return E_NOTIMPL;
 }
 
-static HRESULT WINAPI CompositeMonikerCF_QueryInterface(LPCLASSFACTORY iface,
-                                                  REFIID riid, LPVOID *ppv)
+static HRESULT WINAPI CompositeMonikerCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index 9b32da6..3e5e99c 100644 (file)
@@ -2151,7 +2151,7 @@ static void WINAPI DataCache_OnDataChange(IAdviseSink *iface, FORMATETC *fmt, ST
 {
     DataCache *This = impl_from_IAdviseSink(iface);
     TRACE("(%p)->(%s, %p)\n", This, debugstr_formatetc(fmt), med);
-    IOleCache_SetData(&This->IOleCache2_iface, fmt, med, FALSE);
+    IOleCache2_SetData(&This->IOleCache2_iface, fmt, med, FALSE);
 }
 
 static void WINAPI DataCache_OnViewChange(IAdviseSink *iface, DWORD aspect, LONG index)
index 7b828dd..4517b46 100644 (file)
 
 import "unknwn.idl";
 
-#ifdef __WIDL__
 [
     threading(both),
     uuid(00000320-0000-0000-c000-000000000046)
 ]
 coclass PSFactoryBuffer { interface IFactoryBuffer; }
-#endif
 
 [
   uuid(99fcfe60-5260-101b-bbcb-00aa0021347a),
index 68d85ec..b4e8203 100644 (file)
@@ -58,6 +58,7 @@
 #include "ole2.h"
 
 #include "compobj_private.h"
+#include "storage32.h"
 
 #include "wine/unicode.h"
 #include "wine/debug.h"
@@ -230,7 +231,7 @@ static HRESULT WINAPI DefaultHandler_NDIUnknown_QueryInterface(
   }
   else if (This->inproc_server && This->pOleDelegate)
   {
-    return IUnknown_QueryInterface(This->pOleDelegate, riid, ppvObject);
+    return IOleObject_QueryInterface(This->pOleDelegate, riid, ppvObject);
   }
 
   /* Check that we obtained an interface. */
@@ -1321,7 +1322,7 @@ static HRESULT WINAPI DefaultHandler_Run(
 
   release_delegates(This);
 
-  hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_LOCAL_SERVER,
+  hr = CoCreateInstance(&This->clsid, NULL, CLSCTX_ALL,
                         &IID_IOleObject, (void **)&This->pOleDelegate);
   if (FAILED(hr))
     return hr;
@@ -1583,10 +1584,8 @@ static HRESULT WINAPI DefaultHandler_IPersistStorage_IsDirty(
 }
 
 /***********************************************************************
- *   init_ole_stream
  *
- * Creates the '\1Ole' stream.
- * The format of this stream is as follows:
+ * The format of '\1Ole' stream is as follows:
  *
  * DWORD Version == 0x02000001
  * DWORD Flags - low bit set indicates the object is a link otherwise it's embedded.
@@ -1611,29 +1610,6 @@ typedef struct
 } ole_stream_header_t;
 static const DWORD ole_stream_version = 0x02000001;
 
-static void init_ole_stream(IStorage *storage)
-{
-    HRESULT hr;
-    IStream *stream;
-
-    hr = IStorage_CreateStream(storage, OleStream, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
-    if(SUCCEEDED(hr))
-    {
-        DWORD written;
-        ole_stream_header_t header;
-
-        header.version         = ole_stream_version;
-        header.flags           = 0;
-        header.link_update_opt = 0;
-        header.res             = 0;
-        header.moniker_size    = 0;
-
-        IStream_Write(stream, &header, sizeof(header), &written);
-        IStream_Release(stream);
-    }
-    return;
-}
-
 static HRESULT load_ole_stream(DefaultHandler *This, IStorage *storage)
 {
     IStream *stream;
@@ -1663,10 +1639,8 @@ static HRESULT load_ole_stream(DefaultHandler *This, IStorage *storage)
         IStream_Release(stream);
     }
     else
-    {
-        init_ole_stream(storage);
-        hr = S_OK;
-    }
+        hr = STORAGE_CreateOleStream(storage, 0);
+
     return hr;
 }
 
@@ -1682,7 +1656,8 @@ static HRESULT WINAPI DefaultHandler_IPersistStorage_InitNew(
     HRESULT hr;
 
     TRACE("(%p)->(%p)\n", iface, pStg);
-    init_ole_stream(pStg);
+    hr = STORAGE_CreateOleStream(pStg, 0);
+    if (hr != S_OK) return hr;
 
     hr = IPersistStorage_InitNew(This->dataCache_PersistStg, pStg);
 
@@ -1924,7 +1899,7 @@ static DefaultHandler* DefaultHandler_Construct(
   This->IAdviseSink_iface.lpVtbl = &DefaultHandler_IAdviseSink_VTable;
   This->IPersistStorage_iface.lpVtbl = &DefaultHandler_IPersistStorage_VTable;
 
-  This->inproc_server = (flags & EMBDHLP_INPROC_SERVER) ? TRUE : FALSE;
+  This->inproc_server = (flags & EMBDHLP_INPROC_SERVER) != 0;
 
   /*
    * Start with one reference count. The caller of this function
index 39751ab..b71ee2d 100644 (file)
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
-/* this code is from SysAllocStringLen (ole2disp.c in oleaut32) */
-static BSTR ERRORINFO_SysAllocString(const OLECHAR* in)
-{
-    DWORD  bufferSize;
-    DWORD* newBuffer;
-    WCHAR* stringBuffer;
-    DWORD len;
-
-    if (in == NULL)
-       return NULL;
-    /*
-     * Find the length of the buffer passed-in, in bytes.
-     */
-    len = strlenW(in);
-    bufferSize = len * sizeof (WCHAR);
-
-    /*
-     * Allocate a new buffer to hold the string.
-     * don't forget to keep an empty spot at the beginning of the
-     * buffer for the character count and an extra character at the
-     * end for the '\0'.
-     */
-    newBuffer = HeapAlloc(GetProcessHeap(), 0,
-                                 bufferSize + sizeof(WCHAR) + sizeof(DWORD));
-
-    /*
-     * If the memory allocation failed, return a null pointer.
-     */
-    if (newBuffer==0)
-      return 0;
-
-    /*
-     * Copy the length of the string in the placeholder.
-     */
-    *newBuffer = bufferSize;
-
-    /*
-     * Skip the byte count.
-     */
-    newBuffer++;
-
-    /*
-     * Copy the information in the buffer.  It is not possible to pass 
-     * a NULL pointer here. 
-     */
-    memcpy(newBuffer, in, bufferSize);
-
-    /*
-     * Make sure that there is a nul character at the end of the
-     * string.
-     */
-    stringBuffer = (WCHAR*)newBuffer;
-    stringBuffer[len] = 0;
-
-    return stringBuffer;
+static inline void *heap_alloc(size_t len)
+{
+    return HeapAlloc(GetProcessHeap(), 0, len);
 }
 
-/* this code is from SysFreeString (ole2disp.c in oleaut32)*/
-static VOID ERRORINFO_SysFreeString(BSTR in)
+static inline BOOL heap_free(void *mem)
 {
-    DWORD* bufferPointer;
+    return HeapFree(GetProcessHeap(), 0, mem);
+}
 
-    /* NULL is a valid parameter */
-    if(!in) return;
+static inline WCHAR *heap_strdupW(const WCHAR *str)
+{
+    WCHAR *ret = NULL;
 
-    /*
-     * We have to be careful when we free a BSTR pointer, it points to
-     * the beginning of the string but it skips the byte count contained
-     * before the string.
-     */
-    bufferPointer = (DWORD*)in;
+    if(str) {
+        size_t size;
 
-    bufferPointer--;
+        size = (strlenW(str)+1)*sizeof(WCHAR);
+        ret = heap_alloc(size);
+        if(ret)
+            memcpy(ret, str, size);
+    }
 
-    /*
-     * Free the memory from it's "real" origin.
-     */
-    HeapFree(GetProcessHeap(), 0, bufferPointer);
+    return ret;
 }
 
-
 typedef struct ErrorInfoImpl
 {
-       const IErrorInfoVtbl           *lpvtei;
-       const ICreateErrorInfoVtbl     *lpvtcei;
-       const ISupportErrorInfoVtbl    *lpvtsei;
-       LONG                            ref;
+    IErrorInfo IErrorInfo_iface;
+    ICreateErrorInfo ICreateErrorInfo_iface;
+    ISupportErrorInfo ISupportErrorInfo_iface;
+    LONG ref;
 
-       GUID m_Guid;
-       BSTR bstrSource;
-       BSTR bstrDescription;
-       BSTR bstrHelpFile;
-       DWORD m_dwHelpContext;
+    GUID m_Guid;
+    WCHAR *source;
+    WCHAR *description;
+    WCHAR *help_file;
+    DWORD m_dwHelpContext;
 } ErrorInfoImpl;
 
-static const IErrorInfoVtbl        IErrorInfoImpl_VTable;
-static const ICreateErrorInfoVtbl  ICreateErrorInfoImpl_VTable;
-static const ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable;
-
-/*
- converts an object pointer to This
- */
-
 static inline ErrorInfoImpl *impl_from_IErrorInfo( IErrorInfo *iface )
 {
-    return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtei));
+    return CONTAINING_RECORD(iface, ErrorInfoImpl, IErrorInfo_iface);
 }
 
 static inline ErrorInfoImpl *impl_from_ICreateErrorInfo( ICreateErrorInfo *iface )
 {
-    return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtcei));
+    return CONTAINING_RECORD(iface, ErrorInfoImpl, ICreateErrorInfo_iface);
 }
 
 static inline ErrorInfoImpl *impl_from_ISupportErrorInfo( ISupportErrorInfo *iface )
 {
-    return (ErrorInfoImpl *)((char*)iface - FIELD_OFFSET(ErrorInfoImpl, lpvtsei));
+    return CONTAINING_RECORD(iface, ErrorInfoImpl, ISupportErrorInfo_iface);
 }
 
-
-/*
- converts This to an object pointer
- */
-#define _IErrorInfo_(This)              ((IErrorInfo*)&(This)->lpvtei)
-#define _ICreateErrorInfo_(This)        (&(This)->lpvtcei)
-#define _ISupportErrorInfo_(This)       (&(This)->lpvtsei)
-
-static IErrorInfo * IErrorInfoImpl_Constructor(void)
-{
-       ErrorInfoImpl * ei = HeapAlloc(GetProcessHeap(), 0, sizeof(ErrorInfoImpl));
-       if (ei)
-       {
-         ei->lpvtei = &IErrorInfoImpl_VTable;
-         ei->lpvtcei = &ICreateErrorInfoImpl_VTable;
-         ei->lpvtsei = &ISupportErrorInfoImpl_VTable;
-         ei->ref = 1;
-         ei->bstrSource = NULL;
-         ei->bstrDescription = NULL;
-         ei->bstrHelpFile = NULL;
-         ei->m_dwHelpContext = 0;
-       }
-       return (IErrorInfo *)ei;
-}
-
-
 static HRESULT WINAPI IErrorInfoImpl_QueryInterface(
        IErrorInfo* iface,
        REFIID     riid,
-       VOID**     ppvoid)
+       void**     ppvoid)
 {
        ErrorInfoImpl *This = impl_from_IErrorInfo(iface);
-       TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(riid),ppvoid);
+       TRACE("(%p)->(%s,%p)\n", This, debugstr_guid(riid),ppvoid);
 
        *ppvoid = NULL;
 
-       if(IsEqualIID(riid, &IID_IErrorInfo))
+       if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IErrorInfo))
        {
-         *ppvoid = _IErrorInfo_(This);
+         *ppvoid = &This->IErrorInfo_iface;
        }
        else if(IsEqualIID(riid, &IID_ICreateErrorInfo))
        {
-         *ppvoid = _ICreateErrorInfo_(This);
+         *ppvoid = &This->ICreateErrorInfo_iface;
        }
        else if(IsEqualIID(riid, &IID_ISupportErrorInfo))
        {
-         *ppvoid = _ISupportErrorInfo_(This);
+         *ppvoid = &This->ISupportErrorInfo_iface;
        }
 
        if(*ppvoid)
@@ -238,11 +149,10 @@ static ULONG WINAPI IErrorInfoImpl_Release(
        {
          TRACE("-- destroying IErrorInfo(%p)\n",This);
 
-          ERRORINFO_SysFreeString(This->bstrSource);
-          ERRORINFO_SysFreeString(This->bstrDescription);
-          ERRORINFO_SysFreeString(This->bstrHelpFile);
-         HeapFree(GetProcessHeap(),0,This);
-         return 0;
+          heap_free(This->source);
+          heap_free(This->description);
+          heap_free(This->help_file);
+          heap_free(This);
        }
        return ref;
 }
@@ -266,7 +176,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetSource(
        TRACE("(%p)->(pBstrSource=%p)\n",This,pBstrSource);
        if (pBstrSource == NULL)
            return E_INVALIDARG;
-       *pBstrSource = ERRORINFO_SysAllocString(This->bstrSource);
+       *pBstrSource = SysAllocString(This->source);
        return S_OK;
 }
 
@@ -279,7 +189,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetDescription(
        TRACE("(%p)->(pBstrDescription=%p)\n",This,pBstrDescription);
        if (pBstrDescription == NULL)
            return E_INVALIDARG;
-       *pBstrDescription = ERRORINFO_SysAllocString(This->bstrDescription);
+       *pBstrDescription = SysAllocString(This->description);
 
        return S_OK;
 }
@@ -293,7 +203,7 @@ static HRESULT WINAPI IErrorInfoImpl_GetHelpFile(
        TRACE("(%p)->(pBstrHelpFile=%p)\n",This, pBstrHelpFile);
        if (pBstrHelpFile == NULL)
            return E_INVALIDARG;
-       *pBstrHelpFile = ERRORINFO_SysAllocString(This->bstrHelpFile);
+       *pBstrHelpFile = SysAllocString(This->help_file);
 
        return S_OK;
 }
@@ -311,12 +221,11 @@ static HRESULT WINAPI IErrorInfoImpl_GetHelpContext(
        return S_OK;
 }
 
-static const IErrorInfoVtbl IErrorInfoImpl_VTable =
+static const IErrorInfoVtbl ErrorInfoVtbl =
 {
   IErrorInfoImpl_QueryInterface,
   IErrorInfoImpl_AddRef,
   IErrorInfoImpl_Release,
-
   IErrorInfoImpl_GetGUID,
   IErrorInfoImpl_GetSource,
   IErrorInfoImpl_GetDescription,
@@ -330,25 +239,22 @@ static HRESULT WINAPI ICreateErrorInfoImpl_QueryInterface(
        REFIID     riid,
        VOID**     ppvoid)
 {
-       ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
-       TRACE("(%p)\n", This);
-       return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid);
+    ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
+    return IErrorInfo_QueryInterface(&This->IErrorInfo_iface, riid, ppvoid);
 }
 
 static ULONG WINAPI ICreateErrorInfoImpl_AddRef(
        ICreateErrorInfo* iface)
 {
-       ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
-       TRACE("(%p)\n", This);
-       return IErrorInfo_AddRef(_IErrorInfo_(This));
+    ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
+    return IErrorInfo_AddRef(&This->IErrorInfo_iface);
 }
 
 static ULONG WINAPI ICreateErrorInfoImpl_Release(
        ICreateErrorInfo* iface)
 {
-       ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
-       TRACE("(%p)\n", This);
-       return IErrorInfo_Release(_IErrorInfo_(This));
+    ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
+    return IErrorInfo_Release(&This->IErrorInfo_iface);
 }
 
 
@@ -368,9 +274,9 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetSource(
 {
        ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
        TRACE("(%p): %s\n",This, debugstr_w(szSource));
-       if (This->bstrSource != NULL)
-           ERRORINFO_SysFreeString(This->bstrSource);
-       This->bstrSource = ERRORINFO_SysAllocString(szSource);
+
+       heap_free(This->source);
+       This->source = heap_strdupW(szSource);
 
        return S_OK;
 }
@@ -381,10 +287,9 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetDescription(
 {
        ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
        TRACE("(%p): %s\n",This, debugstr_w(szDescription));
-       if (This->bstrDescription != NULL)
-           ERRORINFO_SysFreeString(This->bstrDescription);
-       This->bstrDescription = ERRORINFO_SysAllocString(szDescription);
 
+       heap_free(This->description);
+       This->description = heap_strdupW(szDescription);
        return S_OK;
 }
 
@@ -394,9 +299,8 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpFile(
 {
        ErrorInfoImpl *This = impl_from_ICreateErrorInfo(iface);
        TRACE("(%p,%s)\n",This,debugstr_w(szHelpFile));
-       if (This->bstrHelpFile != NULL)
-           ERRORINFO_SysFreeString(This->bstrHelpFile);
-       This->bstrHelpFile = ERRORINFO_SysAllocString(szHelpFile);
+       heap_free(This->help_file);
+       This->help_file = heap_strdupW(szHelpFile);
        return S_OK;
 }
 
@@ -410,12 +314,11 @@ static HRESULT WINAPI ICreateErrorInfoImpl_SetHelpContext(
        return S_OK;
 }
 
-static const ICreateErrorInfoVtbl ICreateErrorInfoImpl_VTable =
+static const ICreateErrorInfoVtbl CreateErrorInfoVtbl =
 {
   ICreateErrorInfoImpl_QueryInterface,
   ICreateErrorInfoImpl_AddRef,
   ICreateErrorInfoImpl_Release,
-
   ICreateErrorInfoImpl_SetGUID,
   ICreateErrorInfoImpl_SetSource,
   ICreateErrorInfoImpl_SetDescription,
@@ -428,29 +331,22 @@ static HRESULT WINAPI ISupportErrorInfoImpl_QueryInterface(
        REFIID     riid,
        VOID**     ppvoid)
 {
-       ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
-       TRACE("(%p)\n", This);
-
-       return IErrorInfo_QueryInterface(_IErrorInfo_(This), riid, ppvoid);
+    ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
+    return IErrorInfo_QueryInterface(&This->IErrorInfo_iface, riid, ppvoid);
 }
 
-static ULONG WINAPI ISupportErrorInfoImpl_AddRef(
-       ISupportErrorInfo* iface)
+static ULONG WINAPI ISupportErrorInfoImpl_AddRef(ISupportErrorInfo* iface)
 {
-       ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
-       TRACE("(%p)\n", This);
-       return IErrorInfo_AddRef(_IErrorInfo_(This));
+    ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
+    return IErrorInfo_AddRef(&This->IErrorInfo_iface);
 }
 
-static ULONG WINAPI ISupportErrorInfoImpl_Release(
-       ISupportErrorInfo* iface)
+static ULONG WINAPI ISupportErrorInfoImpl_Release(ISupportErrorInfo* iface)
 {
-       ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
-       TRACE("(%p)\n", This);
-       return IErrorInfo_Release(_IErrorInfo_(This));
+    ErrorInfoImpl *This = impl_from_ISupportErrorInfo(iface);
+    return IErrorInfo_Release(&This->IErrorInfo_iface);
 }
 
-
 static HRESULT WINAPI ISupportErrorInfoImpl_InterfaceSupportsErrorInfo(
        ISupportErrorInfo* iface,
        REFIID riid)
@@ -460,16 +356,32 @@ static HRESULT WINAPI ISupportErrorInfoImpl_InterfaceSupportsErrorInfo(
        return (IsEqualIID(riid, &This->m_Guid)) ? S_OK : S_FALSE;
 }
 
-static const ISupportErrorInfoVtbl ISupportErrorInfoImpl_VTable =
+static const ISupportErrorInfoVtbl SupportErrorInfoVtbl =
 {
   ISupportErrorInfoImpl_QueryInterface,
   ISupportErrorInfoImpl_AddRef,
   ISupportErrorInfoImpl_Release,
-
-
   ISupportErrorInfoImpl_InterfaceSupportsErrorInfo
 };
 
+static IErrorInfo* IErrorInfoImpl_Constructor(void)
+{
+    ErrorInfoImpl *This = heap_alloc(sizeof(ErrorInfoImpl));
+
+    if (!This) return NULL;
+
+    This->IErrorInfo_iface.lpVtbl = &ErrorInfoVtbl;
+    This->ICreateErrorInfo_iface.lpVtbl = &CreateErrorInfoVtbl;
+    This->ISupportErrorInfo_iface.lpVtbl = &SupportErrorInfoVtbl;
+    This->ref = 1;
+    This->source = NULL;
+    This->description = NULL;
+    This->help_file = NULL;
+    This->m_dwHelpContext = 0;
+
+    return &This->IErrorInfo_iface;
+}
+
 /***********************************************************************
  *             CreateErrorInfo (OLE32.@)
  *
index ac0263c..ce74566 100644 (file)
@@ -141,7 +141,7 @@ HRESULT FileLockBytesImpl_Construct(HANDLE hFile, DWORD openFlags, LPCWSTR pwcsN
 static HRESULT WINAPI FileLockBytesImpl_QueryInterface(ILockBytes *iface, REFIID riid,
     void **ppvObject)
 {
-    if (IsEqualIID(riid, &IID_ILockBytes) || IsEqualIID(riid, &IID_ILockBytes))
+    if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_ILockBytes))
         *ppvObject = iface;
     else
     {
index 80f3cc8..7a97100 100644 (file)
@@ -657,6 +657,15 @@ FileMonikerImpl_Reduce(IMoniker* iface, IBindCtx* pbc, DWORD dwReduceHowFar,
     return MK_S_REDUCED_TO_SELF;
 }
 
+static void free_stringtable(LPOLESTR *stringTable)
+{
+    int i;
+
+    for (i=0; stringTable[i]!=NULL; i++)
+        CoTaskMemFree(stringTable[i]);
+    CoTaskMemFree(stringTable);
+}
+
 /******************************************************************************
  *        FileMoniker_ComposeWith
  */
@@ -711,31 +720,28 @@ FileMonikerImpl_ComposeWith(IMoniker* iface, IMoniker* pmkRight,
         /* the length of the composed path string  is raised by the sum of the two paths lengths  */
         newStr=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(lstrlenW(str1)+lstrlenW(str2)+1));
 
-         if (newStr==NULL)
-               return E_OUTOFMEMORY;
-
-        /* new path is the concatenation of the rest of str1 and str2 */
-        for(*newStr=0,j=0;j<=lastIdx1;j++)
-            strcatW(newStr,strDec1[j]);
+        if (newStr)
+        {
+            /* new path is the concatenation of the rest of str1 and str2 */
+            for(*newStr=0,j=0;j<=lastIdx1;j++)
+                strcatW(newStr,strDec1[j]);
 
-        if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
-            strcatW(newStr,bkSlash);
+            if ((strDec2[i]==NULL && lastIdx1>-1 && lastIdx2>-1) || lstrcmpW(strDec2[i],bkSlash)!=0)
+                strcatW(newStr,bkSlash);
 
-        for(j=i;j<=lastIdx2;j++)
-            strcatW(newStr,strDec2[j]);
+            for(j=i;j<=lastIdx2;j++)
+                strcatW(newStr,strDec2[j]);
 
-        /* create a new moniker with the new string */
-        res=CreateFileMoniker(newStr,ppmkComposite);
+            /* create a new moniker with the new string */
+            res=CreateFileMoniker(newStr,ppmkComposite);
 
-        /* free all strings space memory used by this function */
-        HeapFree(GetProcessHeap(),0,newStr);
+            /* free all strings space memory used by this function */
+            HeapFree(GetProcessHeap(),0,newStr);
+        }
+        else res = E_OUTOFMEMORY;
 
-        for(i=0; strDec1[i]!=NULL;i++)
-            CoTaskMemFree(strDec1[i]);
-        for(i=0; strDec2[i]!=NULL;i++)
-            CoTaskMemFree(strDec2[i]);
-        CoTaskMemFree(strDec1);
-        CoTaskMemFree(strDec2);
+        free_stringtable(strDec1);
+        free_stringtable(strDec2);
 
         CoTaskMemFree(str1);
         CoTaskMemFree(str2);
@@ -967,10 +973,17 @@ FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** p
             return nb1;
         nb2=FileMonikerImpl_DecomposePath(pathOther,&stringTable2);
         if (FAILED(nb2))
+        {
+            free_stringtable(stringTable1);
             return nb2;
+        }
 
         if (nb1==0 || nb2==0)
+        {
+            free_stringtable(stringTable1);
+            free_stringtable(stringTable2);
             return MK_E_NOPREFIX;
+        }
 
         commonPath=HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*(min(lstrlenW(pathThis),lstrlenW(pathOther))+1));
         if (!commonPath)
@@ -1003,17 +1016,9 @@ FileMonikerImpl_CommonPrefixWith(IMoniker* iface,IMoniker* pmkOther,IMoniker** p
         {
             for(i=0;i<sameIdx;i++)
                 strcatW(commonPath,stringTable1[i]);
-    
-            for(i=0;i<nb1;i++)
-                CoTaskMemFree(stringTable1[i]);
-    
-            CoTaskMemFree(stringTable1);
-    
-            for(i=0;i<nb2;i++)
-                CoTaskMemFree(stringTable2[i]);
-    
-            CoTaskMemFree(stringTable2);
-    
+
+            free_stringtable(stringTable1);
+            free_stringtable(stringTable2);
             ret = CreateFileMoniker(commonPath,ppmkPrefix);
         }
         HeapFree(GetProcessHeap(),0,commonPath);
@@ -1138,10 +1143,15 @@ FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppm
        return res;
 
     len1=FileMonikerImpl_DecomposePath(str1,&tabStr1);
+    if (FAILED(len1))
+        return E_OUTOFMEMORY;
     len2=FileMonikerImpl_DecomposePath(str2,&tabStr2);
 
-    if (FAILED(len1) || FAILED(len2))
-       return E_OUTOFMEMORY;
+    if (FAILED(len2))
+    {
+        free_stringtable(tabStr1);
+        return E_OUTOFMEMORY;
+    }
 
     /* count the number of similar items from the begin of the two paths */
     for(sameIdx=0; ( (tabStr1[sameIdx]!=NULL) &&
@@ -1166,12 +1176,8 @@ FileMonikerImpl_RelativePathTo(IMoniker* iface,IMoniker* pmOther, IMoniker** ppm
 
     res=CreateFileMoniker(relPath,ppmkRelPath);
 
-    for(j=0; tabStr1[j]!=NULL;j++)
-        CoTaskMemFree(tabStr1[j]);
-    for(j=0; tabStr2[j]!=NULL;j++)
-        CoTaskMemFree(tabStr2[j]);
-    CoTaskMemFree(tabStr1);
-    CoTaskMemFree(tabStr2);
+    free_stringtable(tabStr1);
+    free_stringtable(tabStr2);
     CoTaskMemFree(str1);
     CoTaskMemFree(str2);
     HeapFree(GetProcessHeap(),0,relPath);
@@ -1409,9 +1415,7 @@ static HRESULT FileMonikerImpl_Construct(FileMonikerImpl* This, LPCOLESTR lpszPa
             strcatW(This->filePathName,bkSlash);
     }
 
-    for(i=0; tabStr[i]!=NULL;i++)
-        CoTaskMemFree(tabStr[i]);
-    CoTaskMemFree(tabStr);
+    free_stringtable(tabStr);
 
     return S_OK;
 }
@@ -1555,7 +1559,7 @@ static HRESULT WINAPI FileMonikerCF_QueryInterface(LPCLASSFACTORY iface,
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index 9e58444..21d9c9a 100644 (file)
@@ -358,7 +358,7 @@ static HRESULT WINAPI FTMarshalCF_QueryInterface(LPCLASSFACTORY iface,
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index a4857d4..2e70e44 100644 (file)
@@ -457,7 +457,7 @@ HRESULT WINAPI CoRegisterMallocSpy(LPMALLOCSPY pMallocSpy)
 
         EnterCriticalSection(&IMalloc32_SpyCS);
 
-       if (SUCCEEDED(IUnknown_QueryInterface(pMallocSpy, &IID_IMallocSpy, (LPVOID*)&pSpy))) {
+       if (SUCCEEDED(IMallocSpy_QueryInterface(pMallocSpy, &IID_IMallocSpy, (void**)&pSpy))) {
            Malloc32.pSpy = pSpy;
            hres = S_OK;
        }
index 32f7043..4dc15ba 100644 (file)
@@ -952,14 +952,13 @@ HRESULT WINAPI CreateItemMoniker(LPCOLESTR lpszDelim, LPCOLESTR  lpszItem, IMoni
                                           (void**)ppmk);
 }
 
-static HRESULT WINAPI ItemMonikerCF_QueryInterface(LPCLASSFACTORY iface,
-                                                  REFIID riid, LPVOID *ppv)
+static HRESULT WINAPI ItemMonikerCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index ab1d332..a8df28c 100644 (file)
@@ -55,9 +55,9 @@ extern const CLSID CLSID_DfMarshal;
 /* imported object / proxy manager */
 struct proxy_manager
 {
-  const IMultiQIVtbl *lpVtbl;
-  const IMarshalVtbl *lpVtblMarshal;
-  const IClientSecurityVtbl *lpVtblCliSec;
+  IMultiQI IMultiQI_iface;
+  IMarshal IMarshal_iface;
+  IClientSecurity IClientSecurity_iface;
   struct apartment *parent; /* owning apartment (RO) */
   struct list entry;        /* entry in apartment (CS parent->cs) */
   OXID oxid;                /* object exported ID (RO) */
@@ -75,12 +75,12 @@ struct proxy_manager
 
 static inline struct proxy_manager *impl_from_IMarshal( IMarshal *iface )
 {
-    return (struct proxy_manager *)((char*)iface - FIELD_OFFSET(struct proxy_manager, lpVtblMarshal));
+    return CONTAINING_RECORD(iface, struct proxy_manager, IMarshal_iface);
 }
 
 static inline struct proxy_manager *impl_from_IClientSecurity( IClientSecurity *iface )
 {
-    return (struct proxy_manager *)((char*)iface - FIELD_OFFSET(struct proxy_manager, lpVtblCliSec));
+    return CONTAINING_RECORD(iface, struct proxy_manager, IClientSecurity_iface);
 }
 
 static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
@@ -115,7 +115,8 @@ static inline HRESULT get_facbuf_for_iid(REFIID riid, IPSFactoryBuffer **facbuf)
 }
 
 /* marshals an object into a STDOBJREF structure */
-HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *object, MSHLFLAGS mshlflags)
+HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnknown *object,
+    DWORD dest_context, void *dest_context_data, MSHLFLAGS mshlflags)
 {
     struct stub_manager *manager;
     struct ifstub       *ifstub;
@@ -192,7 +193,7 @@ HRESULT marshal_object(APARTMENT *apt, STDOBJREF *stdobjref, REFIID riid, IUnkno
     /* make sure ifstub that we are creating is unique */
     ifstub = stub_manager_find_ifstub(manager, riid, mshlflags);
     if (!ifstub)
-        ifstub = stub_manager_new_ifstub(manager, stub, iobject, riid, mshlflags);
+        ifstub = stub_manager_new_ifstub(manager, stub, iobject, riid, dest_context, dest_context_data, mshlflags);
 
     if (stub) IRpcStubBuffer_Release(stub);
     IUnknown_Release(iobject);
@@ -384,19 +385,19 @@ static HRESULT WINAPI StdMarshalImpl_DisconnectObject(LPMARSHAL iface, DWORD dwR
 static HRESULT WINAPI Proxy_QueryInterface(IMarshal *iface, REFIID riid, void **ppvObject)
 {
     struct proxy_manager *This = impl_from_IMarshal( iface );
-    return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
+    return IMultiQI_QueryInterface(&This->IMultiQI_iface, riid, ppvObject);
 }
 
 static ULONG WINAPI Proxy_AddRef(IMarshal *iface)
 {
     struct proxy_manager *This = impl_from_IMarshal( iface );
-    return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
+    return IMultiQI_AddRef(&This->IMultiQI_iface);
 }
 
 static ULONG WINAPI Proxy_Release(IMarshal *iface)
 {
     struct proxy_manager *This = impl_from_IMarshal( iface );
-    return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
+    return IMultiQI_Release(&This->IMultiQI_iface);
 }
 
 static HRESULT WINAPI Proxy_MarshalInterface(
@@ -529,19 +530,19 @@ static const IMarshalVtbl ProxyMarshal_Vtbl =
 static HRESULT WINAPI ProxyCliSec_QueryInterface(IClientSecurity *iface, REFIID riid, void **ppvObject)
 {
     struct proxy_manager *This = impl_from_IClientSecurity( iface );
-    return IMultiQI_QueryInterface((IMultiQI *)&This->lpVtbl, riid, ppvObject);
+    return IMultiQI_QueryInterface(&This->IMultiQI_iface, riid, ppvObject);
 }
 
 static ULONG WINAPI ProxyCliSec_AddRef(IClientSecurity *iface)
 {
     struct proxy_manager *This = impl_from_IClientSecurity( iface );
-    return IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
+    return IMultiQI_AddRef(&This->IMultiQI_iface);
 }
 
 static ULONG WINAPI ProxyCliSec_Release(IClientSecurity *iface)
 {
     struct proxy_manager *This = impl_from_IClientSecurity( iface );
-    return IMultiQI_Release((IMultiQI *)&This->lpVtbl);
+    return IMultiQI_Release(&This->IMultiQI_iface);
 }
 
 static HRESULT WINAPI ProxyCliSec_QueryBlanket(IClientSecurity *iface,
@@ -753,9 +754,9 @@ static HRESULT proxy_manager_construct(
         }
     }
 
-    This->lpVtbl = &ClientIdentity_Vtbl;
-    This->lpVtblMarshal = &ProxyMarshal_Vtbl;
-    This->lpVtblCliSec = &ProxyCliSec_Vtbl;
+    This->IMultiQI_iface.lpVtbl = &ClientIdentity_Vtbl;
+    This->IMarshal_iface.lpVtbl = &ProxyMarshal_Vtbl;
+    This->IClientSecurity_iface.lpVtbl = &ProxyCliSec_Vtbl;
 
     list_init(&This->entry);
     list_init(&This->interfaces);
@@ -868,20 +869,20 @@ static HRESULT proxy_manager_query_local_interface(struct proxy_manager * This,
     if (IsEqualIID(riid, &IID_IUnknown) ||
         IsEqualIID(riid, &IID_IMultiQI))
     {
-        *ppv = &This->lpVtbl;
-        IUnknown_AddRef((IUnknown *)*ppv);
+        *ppv = &This->IMultiQI_iface;
+        IMultiQI_AddRef(&This->IMultiQI_iface);
         return S_OK;
     }
     if (IsEqualIID(riid, &IID_IMarshal))
     {
-        *ppv = &This->lpVtblMarshal;
-        IUnknown_AddRef((IUnknown *)*ppv);
+        *ppv = &This->IMarshal_iface;
+        IMarshal_AddRef(&This->IMarshal_iface);
         return S_OK;
     }
     if (IsEqualIID(riid, &IID_IClientSecurity))
     {
-        *ppv = &This->lpVtblCliSec;
-        IUnknown_AddRef((IUnknown *)*ppv);
+        *ppv = &This->IClientSecurity_iface;
+        IClientSecurity_AddRef(&This->IClientSecurity_iface);
         return S_OK;
     }
 
@@ -921,8 +922,8 @@ static HRESULT proxy_manager_create_ifproxy(
      * proxy associated with the ifproxy as we handle IUnknown ourselves */
     if (IsEqualIID(riid, &IID_IUnknown))
     {
-        ifproxy->iface = &This->lpVtbl;
-        IMultiQI_AddRef((IMultiQI *)&This->lpVtbl);
+        ifproxy->iface = &This->IMultiQI_iface;
+        IMultiQI_AddRef(&This->IMultiQI_iface);
         hr = S_OK;
     }
     else
@@ -934,7 +935,7 @@ static HRESULT proxy_manager_create_ifproxy(
              * This ensures the COM identity rules are not violated, by having a
              * one-to-one mapping of objects on the proxy side to objects on the
              * stub side, no matter which interface you view the object through */
-            hr = IPSFactoryBuffer_CreateProxy(psfb, (IUnknown *)&This->lpVtbl, riid,
+            hr = IPSFactoryBuffer_CreateProxy(psfb, (IUnknown*)&This->IMultiQI_iface, riid,
                                               &ifproxy->proxy, &ifproxy->iface);
             IPSFactoryBuffer_Release(psfb);
             if (hr != S_OK)
@@ -1137,7 +1138,7 @@ static BOOL find_proxy_manager(APARTMENT * apt, OXID oxid, OID oid, struct proxy
             /* be careful of a race with ClientIdentity_Release, which would
              * cause us to return a proxy which is in the process of being
              * destroyed */
-            if (ClientIdentity_AddRef((IMultiQI *)&proxy->lpVtbl) != 0)
+            if (IMultiQI_AddRef(&proxy->IMultiQI_iface) != 0)
             {
                 *proxy_found = proxy;
                 found = TRUE;
@@ -1175,13 +1176,13 @@ typedef struct _StdMarshalImpl
 } StdMarshalImpl;
 
 static HRESULT WINAPI 
-StdMarshalImpl_QueryInterface(LPMARSHAL iface, REFIID riid, LPVOID *ppv)
+StdMarshalImpl_QueryInterface(IMarshal *iface, REFIID riid, void **ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(&IID_IUnknown, riid) || IsEqualIID(&IID_IMarshal, riid))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IMarshal_AddRef(iface);
         return S_OK;
     }
     FIXME("No interface for %s.\n", debugstr_guid(riid));
@@ -1225,8 +1226,8 @@ StdMarshalImpl_GetMarshalSizeMax(
 
 static HRESULT WINAPI
 StdMarshalImpl_MarshalInterface(
-    LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dwDestContext,
-    void* pvDestContext, DWORD mshlflags)
+    LPMARSHAL iface, IStream *pStm,REFIID riid, void* pv, DWORD dest_context,
+    void* dest_context_data, DWORD mshlflags)
 {
     STDOBJREF             stdobjref;
     ULONG                 res;
@@ -1244,7 +1245,7 @@ StdMarshalImpl_MarshalInterface(
     /* make sure this apartment can be reached from other threads / processes */
     RPC_StartRemoting(apt);
 
-    hres = marshal_object(apt, &stdobjref, riid, pv, mshlflags);
+    hres = marshal_object(apt, &stdobjref, riid, pv, dest_context, dest_context_data, mshlflags);
     if (hres != S_OK)
     {
         ERR("Failed to create ifstub, hres=0x%x\n", hres);
@@ -1321,7 +1322,7 @@ static HRESULT unmarshal_object(const STDOBJREF *stdobjref, APARTMENT *apt,
 
     /* release our reference to the proxy manager - the client/apartment
      * will hold on to the remaining reference for us */
-    if (proxy_manager) ClientIdentity_Release((IMultiQI*)&proxy_manager->lpVtbl);
+    if (proxy_manager) IMultiQI_Release(&proxy_manager->IMultiQI_iface);
 
     return hr;
 }
index 87bbfcb..81d3b32 100644 (file)
@@ -48,16 +48,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(ole);
  */
 struct HGLOBALLockBytesImpl
 {
-  /*
-   * Needs to be the first item in the struct
-   * since we want to cast this in an ILockBytes pointer
-   */
-  const ILockBytesVtbl *lpVtbl;
-
-  /*
-   * Reference count
-   */
-  LONG        ref;
+  ILockBytes ILockBytes_iface;
+  LONG ref;
 
   /*
    * Support for the LockBytes object
@@ -78,16 +70,10 @@ struct HGLOBALLockBytesImpl
 
 typedef struct HGLOBALLockBytesImpl HGLOBALLockBytesImpl;
 
-/*
- * Method definition for the HGLOBALLockBytesImpl class.
- */
-static HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct(
-    HGLOBAL  hGlobal,
-    BOOL     fDeleteOnRelease);
-
-static void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This);
-
-static HRESULT WINAPI HGLOBALLockBytesImpl_SetSize( ILockBytes* iface, ULARGE_INTEGER libNewSize );
+static inline HGLOBALLockBytesImpl *impl_from_ILockBytes( ILockBytes *iface )
+{
+    return CONTAINING_RECORD(iface, HGLOBALLockBytesImpl, ILockBytes_iface);
+}
 
 static const ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl;
 
@@ -98,9 +84,9 @@ static const ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl;
  * This object supports a COM implementation of the ILockBytes interface.
  *
  * PARAMS
- *  hGlobal           [ I] Global memory handle
- *  fDeleteOnRelease  [ I] Whether the handle should be freed when the object is released. 
- *  ppLkbyt           [ O] Address of ILockBytes pointer that receives
+ *  global            [ I] Global memory handle
+ *  delete_on_release [ I] Whether the handle should be freed when the object is released.
+ *  ret               [ O] Address of ILockBytes pointer that receives
  *                         the interface pointer to the new byte array object.
  *
  * RETURNS
@@ -112,22 +98,37 @@ static const ILockBytesVtbl HGLOBALLockBytesImpl_Vtbl;
  *  The ILockBytes interface instance calls the GlobalReAlloc function to grow
  *  the memory block as required.
  */
-HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL      hGlobal,
-                                         BOOL         fDeleteOnRelease,
-                                         LPLOCKBYTES* ppLkbyt)
+HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL global, BOOL delete_on_release, ILockBytes **ret)
 {
-  HGLOBALLockBytesImpl* newLockBytes;
+  HGLOBALLockBytesImpl* lockbytes;
 
-  newLockBytes = HGLOBALLockBytesImpl_Construct(hGlobal, fDeleteOnRelease);
+  lockbytes = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALLockBytesImpl));
+  if (!lockbytes) return E_OUTOFMEMORY;
 
-  if (newLockBytes != NULL)
-  {
-    return IUnknown_QueryInterface((IUnknown*)newLockBytes,
-                                   &IID_ILockBytes,
-                                   (void**)ppLkbyt);
-  }
+  lockbytes->ILockBytes_iface.lpVtbl = &HGLOBALLockBytesImpl_Vtbl;
+  lockbytes->ref = 1;
+
+  /*
+   * Initialize the support.
+   */
+  lockbytes->supportHandle = global;
+  lockbytes->deleteOnRelease = delete_on_release;
+
+  /*
+   * This method will allocate a handle if one is not supplied.
+   */
+  if (lockbytes->supportHandle == 0)
+    lockbytes->supportHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_NODISCARD, 0);
+
+  /*
+   * Initialize the size of the array to the size of the handle.
+   */
+  lockbytes->byteArraySize.u.HighPart = 0;
+  lockbytes->byteArraySize.u.LowPart  = GlobalSize(lockbytes->supportHandle);
 
-  return E_OUTOFMEMORY;
+  *ret = &lockbytes->ILockBytes_iface;
+
+  return S_OK;
 }
 
 /******************************************************************************
@@ -144,23 +145,23 @@ HRESULT WINAPI CreateILockBytesOnHGlobal(HGLOBAL      hGlobal,
  *  E_INVALIDARG  if any parameters are invalid
  *  
  */
-HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* plkbyt, HGLOBAL* phglobal)
+HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* iface, HGLOBAL* phglobal)
 {
-  HGLOBALLockBytesImpl* const pMemLockBytes = (HGLOBALLockBytesImpl*)plkbyt;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
   STATSTG stbuf;
   HRESULT hres;
   ULARGE_INTEGER start;
   ULONG xread;
 
   *phglobal = 0;
-  if (pMemLockBytes->lpVtbl == &HGLOBALLockBytesImpl_Vtbl) {
-    *phglobal = pMemLockBytes->supportHandle;
+  if (This->ILockBytes_iface.lpVtbl == &HGLOBALLockBytesImpl_Vtbl) {
+    *phglobal = This->supportHandle;
     if (*phglobal == 0)
       return E_INVALIDARG;
     return S_OK;
   }
   /* It is not our lockbytes implementation, so use a more generic way */
-  hres = ILockBytes_Stat(plkbyt,&stbuf,STATFLAG_NONAME);
+  hres = ILockBytes_Stat(iface,&stbuf,STATFLAG_NONAME);
   if (hres != S_OK) {
      ERR("Cannot ILockBytes_Stat, %x\n",hres);
      return hres;
@@ -170,10 +171,10 @@ HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* plkbyt, HGLOBAL* phglobal)
   if (!*phglobal)
     return E_INVALIDARG;
   memset(&start,0,sizeof(start));
-  hres = ILockBytes_ReadAt(plkbyt, start, GlobalLock(*phglobal), stbuf.cbSize.u.LowPart, &xread);
+  hres = ILockBytes_ReadAt(iface, start, GlobalLock(*phglobal), stbuf.cbSize.u.LowPart, &xread);
   GlobalUnlock(*phglobal);
   if (hres != S_OK) {
-    FIXME("%p->ReadAt failed with %x\n",plkbyt,hres);
+    FIXME("%p->ReadAt failed with %x\n",iface,hres);
     return hres;
   }
   if (stbuf.cbSize.u.LowPart != xread) {
@@ -188,79 +189,6 @@ HRESULT WINAPI GetHGlobalFromILockBytes(ILockBytes* plkbyt, HGLOBAL* phglobal)
  *
  */
 
-/******************************************************************************
- * This is the constructor for the HGLOBALLockBytesImpl class.
- *
- * PARAMS
- *    hGlobal          [ I] Handle that will support the stream. can be NULL.
- *    fDeleteOnRelease [ I] Flag set to TRUE if the HGLOBAL will be released
- *                          when the IStream object is destroyed.
- */
-static HGLOBALLockBytesImpl* HGLOBALLockBytesImpl_Construct(HGLOBAL hGlobal,
-                                                            BOOL    fDeleteOnRelease)
-{
-  HGLOBALLockBytesImpl* newLockBytes;
-  newLockBytes = HeapAlloc(GetProcessHeap(), 0, sizeof(HGLOBALLockBytesImpl));
-
-  if (newLockBytes!=0)
-  {
-    /*
-     * Set up the virtual function table and reference count.
-     */
-    newLockBytes->lpVtbl = &HGLOBALLockBytesImpl_Vtbl;
-    newLockBytes->ref    = 0;
-
-    /*
-     * Initialize the support.
-     */
-    newLockBytes->supportHandle = hGlobal;
-    newLockBytes->deleteOnRelease = fDeleteOnRelease;
-
-    /*
-     * This method will allocate a handle if one is not supplied.
-     */
-    if (newLockBytes->supportHandle == 0)
-    {
-      newLockBytes->supportHandle = GlobalAlloc(GMEM_MOVEABLE |
-                                                GMEM_NODISCARD,
-                                                0);
-    }
-
-    /*
-     * Initialize the size of the array to the size of the handle.
-     */
-    newLockBytes->byteArraySize.u.HighPart = 0;
-    newLockBytes->byteArraySize.u.LowPart  = GlobalSize(
-                                              newLockBytes->supportHandle);
-  }
-
-  return newLockBytes;
-}
-
-/******************************************************************************
- * This is the destructor of the HGLOBALStreamImpl class.
- *
- * This method will clean-up all the resources used-up by the given
- * HGLOBALLockBytesImpl class. The pointer passed-in to this function will be
- * freed and will not be valid anymore.
- */
-static void HGLOBALLockBytesImpl_Destroy(HGLOBALLockBytesImpl* This)
-{
-  /*
-   * Release the HGlobal if the constructor asked for that.
-   */
-  if (This->deleteOnRelease)
-  {
-    GlobalFree(This->supportHandle);
-    This->supportHandle = 0;
-  }
-
-  /*
-   * Finally, free the memory used-up by the class.
-   */
-  HeapFree(GetProcessHeap(), 0, This);
-}
-
 /******************************************************************************
  * This implements the IUnknown method QueryInterface for this
  * class
@@ -270,39 +198,22 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface(
       REFIID       riid,        /* [in] */
       void**       ppvObject)   /* [iid_is][out] */
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
 
-  /*
-   * Perform a sanity check on the parameters.
-   */
   if (ppvObject==0)
     return E_INVALIDARG;
 
-  /*
-   * Initialize the return parameter.
-   */
   *ppvObject = 0;
 
-  /*
-   * Compare the riid with the interface IDs implemented by this object.
-   */
   if (IsEqualIID(riid, &IID_IUnknown) ||
       IsEqualIID(riid, &IID_ILockBytes))
   {
-    *ppvObject = This;
+    *ppvObject = &This->ILockBytes_iface;
   }
-
-  /*
-   * Check that we obtained an interface.
-   */
-  if ((*ppvObject)==0)
+  else
     return E_NOINTERFACE;
 
-  /*
-   * Query Interface always increases the reference count by one when it is
-   * successful
-   */
-  IUnknown_AddRef(iface);
+  ILockBytes_AddRef(iface);
 
   return S_OK;
 }
@@ -313,7 +224,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_QueryInterface(
  */
 static ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
   return InterlockedIncrement(&This->ref);
 }
 
@@ -323,17 +234,18 @@ static ULONG WINAPI HGLOBALLockBytesImpl_AddRef(ILockBytes* iface)
  */
 static ULONG WINAPI HGLOBALLockBytesImpl_Release(ILockBytes* iface)
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
   ULONG ref;
 
   ref = InterlockedDecrement(&This->ref);
-
-  /*
-   * If the reference count goes down to 0, perform suicide.
-   */
-  if (ref==0)
+  if (!ref)
   {
-    HGLOBALLockBytesImpl_Destroy(This);
+    if (This->deleteOnRelease)
+    {
+      GlobalFree(This->supportHandle);
+      This->supportHandle = 0;
+    }
+    HeapFree(GetProcessHeap(), 0, This);
   }
 
   return ref;
@@ -354,7 +266,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_ReadAt(
       ULONG          cb,        /* [in] */
       ULONG*         pcbRead)   /* [out] */
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
 
   void* supportBuffer;
   ULONG bytesReadBuffer = 0;
@@ -426,7 +338,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_WriteAt(
       ULONG          cb,          /* [in] */
       ULONG*         pcbWritten)  /* [out] */
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
 
   void*          supportBuffer;
   ULARGE_INTEGER newSize;
@@ -455,7 +367,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_WriteAt(
   if (newSize.u.LowPart > This->byteArraySize.u.LowPart)
   {
     /* grow stream */
-    if (HGLOBALLockBytesImpl_SetSize(iface, newSize) == STG_E_MEDIUMFULL)
+    if (ILockBytes_SetSize(iface, newSize) == STG_E_MEDIUMFULL)
       return STG_E_MEDIUMFULL;
   }
 
@@ -500,7 +412,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_SetSize(
       ILockBytes*     iface,
       ULARGE_INTEGER  libNewSize)   /* [in] */
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
   HGLOBAL supportHandle;
 
   /*
@@ -571,7 +483,7 @@ static HRESULT WINAPI HGLOBALLockBytesImpl_Stat(
       STATSTG*     pstatstg,     /* [out] */
       DWORD        grfStatFlag)  /* [in] */
 {
-  HGLOBALLockBytesImpl* const This=(HGLOBALLockBytesImpl*)iface;
+  HGLOBALLockBytesImpl* This = impl_from_ILockBytes(iface);
 
   memset(pstatstg, 0, sizeof(STATSTG));
 
index 91f0499..1d7f219 100644 (file)
@@ -192,7 +192,7 @@ static void rot_entry_delete(struct rot_entry *rot_entry)
             if (hr == S_OK)
             {
                 CoReleaseMarshalData(stream);
-                IUnknown_Release(stream);
+                IStream_Release(stream);
             }
         }
         MIDL_user_free(moniker);
@@ -205,7 +205,7 @@ static void rot_entry_delete(struct rot_entry *rot_entry)
         if (hr == S_OK)
         {
             CoReleaseMarshalData(stream);
-            IUnknown_Release(stream);
+            IStream_Release(stream);
         }
     }
     HeapFree(GetProcessHeap(), 0, rot_entry->object);
diff --git a/reactos/dll/win32/ole32/msvc-thiscall.c b/reactos/dll/win32/ole32/msvc-thiscall.c
new file mode 100644 (file)
index 0000000..4b2af72
--- /dev/null
@@ -0,0 +1,13 @@
+
+#define DEFINE_THISCALL_WRAPPER(func,args) \
+    typedef struct {int x[args/4];} _tag_##func; \
+    void __stdcall func(_tag_##func p1); \
+    __declspec(naked) void __stdcall func(_tag_##func p1) \
+    { \
+        __asm pop eax \
+        __asm push ecx \
+        __asm push eax \
+        __asm jmp func \
+    }
+
+DEFINE_THISCALL_WRAPPER(Allocate_PMemoryAllocator,8)
diff --git a/reactos/dll/win32/ole32/msvc.h b/reactos/dll/win32/ole32/msvc.h
new file mode 100644 (file)
index 0000000..44d63b9
--- /dev/null
@@ -0,0 +1,2 @@
+
+#define __ASM_STDCALL_FUNC(name,args,code)
index 9e9ca65..1bd4c1a 100644 (file)
@@ -290,7 +290,7 @@ static inline HANDLE get_droptarget_handle(HWND hwnd)
  */
 static inline BOOL is_droptarget(HWND hwnd)
 {
-    return get_droptarget_handle(hwnd) ? TRUE : FALSE;
+    return get_droptarget_handle(hwnd) != 0;
 }
 
 /*************************************************************
@@ -703,10 +703,7 @@ HRESULT WINAPI OleRegGetUserType(
   /*
    * Open the class id Key
    */
-  hres = RegOpenKeyW(HKEY_CLASSES_ROOT,
-                    keyName,
-                    &clsidKey);
-
+  hres = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
   if (hres != ERROR_SUCCESS)
     return REGDB_E_CLASSNOTREG;
 
@@ -902,21 +899,14 @@ HRESULT WINAPI OleRegGetMiscStatus(
   /*
    * Open the class id Key
    */
-  result = RegOpenKeyW(HKEY_CLASSES_ROOT,
-                      keyName,
-                      &clsidKey);
-
+  result = open_classes_key(HKEY_CLASSES_ROOT, keyName, MAXIMUM_ALLOWED, &clsidKey);
   if (result != ERROR_SUCCESS)
     return REGDB_E_CLASSNOTREG;
 
   /*
    * Get the MiscStatus
    */
-  result = RegOpenKeyW(clsidKey,
-                      miscstatusW,
-                      &miscStatusKey);
-
-
+  result = open_classes_key(clsidKey, miscstatusW, MAXIMUM_ALLOWED, &miscStatusKey);
   if (result != ERROR_SUCCESS)
   {
     RegCloseKey(clsidKey);
@@ -933,10 +923,7 @@ HRESULT WINAPI OleRegGetMiscStatus(
    */
   sprintfW(keyName, dfmtW, dwAspect);
 
-  result = RegOpenKeyW(miscStatusKey,
-                      keyName,
-                      &aspectKey);
-
+  result = open_classes_key(miscStatusKey, keyName, MAXIMUM_ALLOWED, &aspectKey);
   if (result == ERROR_SUCCESS)
   {
     OLEUTL_ReadRegistryDWORDValue(aspectKey, pdwStatus);
@@ -975,7 +962,7 @@ static HRESULT WINAPI EnumOLEVERB_QueryInterface(
     if (IsEqualIID(riid, &IID_IUnknown) ||
         IsEqualIID(riid, &IID_IEnumOLEVERB))
     {
-        IUnknown_AddRef(iface);
+        IEnumOLEVERB_AddRef(iface);
         *ppv = iface;
         return S_OK;
     }
@@ -1333,10 +1320,7 @@ HRESULT WINAPI OleLoad(
   /*
    * Initialize the object with its IPersistStorage interface.
    */
-  hres = IOleObject_QueryInterface(pUnk,
-                                   &IID_IPersistStorage,
-                                   (void**)&persistStorage);
-
+  hres = IUnknown_QueryInterface(pUnk, &IID_IPersistStorage, (void**)&persistStorage);
   if (SUCCEEDED(hres))
   {
     hres = IPersistStorage_Load(persistStorage, pStg);
@@ -1660,7 +1644,7 @@ static BOOL OLEMenu_SetIsServerMenu( HMENU hmenu, OleMenuDescriptor *pOleMenuDes
     if ( nPos < nWidth )
     {
       /* Odd elements are server menu widths */
-      pOleMenuDescriptor->bIsServerItem = (i%2) ? TRUE : FALSE;
+      pOleMenuDescriptor->bIsServerItem = i%2;
       break;
     }
   }
@@ -2557,32 +2541,24 @@ HRESULT WINAPI OleDraw(
        IUnknown *pUnk,
        DWORD dwAspect,
        HDC hdcDraw,
-       LPCRECT lprcBounds)
+       LPCRECT rect)
 {
   HRESULT hres;
   IViewObject *viewobject;
 
+  if (!pUnk) return E_INVALIDARG;
+
   hres = IUnknown_QueryInterface(pUnk,
                                 &IID_IViewObject,
                                 (void**)&viewobject);
-
   if (SUCCEEDED(hres))
   {
-    RECTL rectl;
-
-    rectl.left = lprcBounds->left;
-    rectl.right = lprcBounds->right;
-    rectl.top = lprcBounds->top;
-    rectl.bottom = lprcBounds->bottom;
-    hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, &rectl, 0, 0, 0);
-
+    hres = IViewObject_Draw(viewobject, dwAspect, -1, 0, 0, 0, hdcDraw, (RECTL*)rect, 0, 0, 0);
     IViewObject_Release(viewobject);
     return hres;
   }
   else
-  {
     return DV_E_NOIVIEWOBJECT;
-  }
 }
 
 /***********************************************************************
@@ -2816,86 +2792,22 @@ static void OLE_FreeClipDataArray(ULONG count, CLIPDATA * pClipDataArray)
 
 /***********************************************************************
  *           PropSysAllocString                            [OLE32.@]
- * NOTES:
- *  Basically a copy of SysAllocStringLen.
+ * NOTES
+ *  Forward to oleaut32.
  */
 BSTR WINAPI PropSysAllocString(LPCOLESTR str)
 {
-    DWORD  bufferSize;
-    DWORD* newBuffer;
-    WCHAR* stringBuffer;
-    int len;
-
-    if (!str) return 0;
-
-    len = lstrlenW(str);
-    /*
-     * Find the length of the buffer passed-in, in bytes.
-     */
-    bufferSize = len * sizeof (WCHAR);
-
-    /*
-     * Allocate a new buffer to hold the string.
-     * Don't forget to keep an empty spot at the beginning of the
-     * buffer for the character count and an extra character at the
-     * end for the NULL.
-     */
-    newBuffer = HeapAlloc(GetProcessHeap(), 0,
-                          bufferSize + sizeof(WCHAR) + sizeof(DWORD));
-
-    /*
-     * If the memory allocation failed, return a null pointer.
-     */
-    if (newBuffer==0)
-      return 0;
-
-    /*
-     * Copy the length of the string in the placeholder.
-     */
-    *newBuffer = bufferSize;
-
-    /*
-     * Skip the byte count.
-     */
-    newBuffer++;
-
-    memcpy(newBuffer, str, bufferSize);
-
-    /*
-     * Make sure that there is a nul character at the end of the
-     * string.
-     */
-    stringBuffer = (WCHAR*)newBuffer;
-    stringBuffer[len] = '\0';
-
-    return stringBuffer;
+    return SysAllocString(str);
 }
 
 /***********************************************************************
  *           PropSysFreeString                     [OLE32.@]
  * NOTES
- *  Copy of SysFreeString.
+ *  Forward to oleaut32.
  */
 void WINAPI PropSysFreeString(LPOLESTR str)
 {
-    DWORD* bufferPointer;
-
-    /* NULL is a valid parameter */
-    if(!str) return;
-
-    /*
-     * We have to be careful when we free a BSTR pointer, it points to
-     * the beginning of the string but it skips the byte count contained
-     * before the string.
-     */
-    bufferPointer = (DWORD*)str;
-
-    bufferPointer--;
-
-    /*
-     * Free the memory from its "real" origin.
-     */
-    HeapFree(GetProcessHeap(), 0, bufferPointer);
+    SysFreeString(str);
 }
 
 /******************************************************************************
@@ -2907,8 +2819,10 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     {
     case VT_EMPTY:
     case VT_NULL:
+    case VT_I1:
     case VT_I2:
     case VT_I4:
+    case VT_I8:
     case VT_R4:
     case VT_R8:
     case VT_CY:
@@ -2920,7 +2834,6 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_UI1:
     case VT_UI2:
     case VT_UI4:
-    case VT_I8:
     case VT_UI8:
     case VT_LPSTR:
     case VT_LPWSTR:
@@ -2933,8 +2846,10 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_BLOB_OBJECT:
     case VT_CF:
     case VT_CLSID:
+    case VT_I1|VT_VECTOR:
     case VT_I2|VT_VECTOR:
     case VT_I4|VT_VECTOR:
+    case VT_I8|VT_VECTOR:
     case VT_R4|VT_VECTOR:
     case VT_R8|VT_VECTOR:
     case VT_CY|VT_VECTOR:
@@ -2946,7 +2861,6 @@ static inline HRESULT PROPVARIANT_ValidateType(VARTYPE vt)
     case VT_UI1|VT_VECTOR:
     case VT_UI2|VT_VECTOR:
     case VT_UI4|VT_VECTOR:
-    case VT_I8|VT_VECTOR:
     case VT_UI8|VT_VECTOR:
     case VT_LPSTR|VT_VECTOR:
     case VT_LPWSTR|VT_VECTOR:
@@ -2979,8 +2893,10 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     {
     case VT_EMPTY:
     case VT_NULL:
+    case VT_I1:
     case VT_I2:
     case VT_I4:
+    case VT_I8:
     case VT_R4:
     case VT_R8:
     case VT_CY:
@@ -2991,7 +2907,6 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     case VT_UI1:
     case VT_UI2:
     case VT_UI4:
-    case VT_I8:
     case VT_UI8:
     case VT_FILETIME:
         break;
@@ -3000,7 +2915,7 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
     case VT_STORAGE:
     case VT_STORED_OBJECT:
         if (pvar->u.pStream)
-            IUnknown_Release(pvar->u.pStream);
+            IStream_Release(pvar->u.pStream);
         break;
     case VT_CLSID:
     case VT_LPSTR:
@@ -3014,8 +2929,7 @@ HRESULT WINAPI PropVariantClear(PROPVARIANT * pvar) /* [in/out] */
         CoTaskMemFree(pvar->u.blob.pBlobData);
         break;
     case VT_BSTR:
-        if (pvar->u.bstrVal)
-            PropSysFreeString(pvar->u.bstrVal);
+        PropSysFreeString(pvar->u.bstrVal);
         break;
     case VT_CF:
         if (pvar->u.pclipdata)
index e4eccc1..5d92fec 100644 (file)
@@ -102,6 +102,8 @@ static inline void init_fmtetc(FORMATETC *fmt, CLIPFORMAT cf, TYMED tymed)
  */
 static HRESULT get_storage(IDataObject *data, IStorage *stg, UINT *src_cf)
 {
+    static const UINT fmt_id[] = { CF_METAFILEPICT, CF_BITMAP, CF_DIB };
+    UINT i;
     HRESULT hr;
     FORMATETC fmt;
     STGMEDIUM med;
@@ -132,6 +134,17 @@ static HRESULT get_storage(IDataObject *data, IStorage *stg, UINT *src_cf)
         return hr;
     }
 
+    for (i = 0; i < sizeof(fmt_id)/sizeof(fmt_id[0]); i++)
+    {
+        init_fmtetc(&fmt, fmt_id[i], TYMED_ISTORAGE);
+        hr = IDataObject_QueryGetData(data, &fmt);
+        if(SUCCEEDED(hr))
+        {
+            *src_cf = fmt_id[i];
+            return hr;
+        }
+    }
+
     /* IPersistStorage */
     hr = IDataObject_QueryInterface(data, &IID_IPersistStorage, (void**)&persist);
     if(FAILED(hr)) return hr;
@@ -196,6 +209,31 @@ HRESULT WINAPI OleCreateFromData(LPDATAOBJECT data, REFIID iid,
                                fmt, NULL, NULL, client_site, stg, obj);
 }
 
+/******************************************************************************
+ *              OleCreateLinkFromData        [OLE32.@]
+ */
+HRESULT WINAPI OleCreateLinkFromData(IDataObject *data, REFIID iid,
+                                     DWORD renderopt, FORMATETC *fmt,
+                                     IOleClientSite *client_site, IStorage *stg,
+                                     void **obj)
+{
+    FIXME("%p,%s,%08x,%p,%p,%p,%p: semi-stub\n",
+          data, debugstr_guid(iid), renderopt, fmt, client_site, stg, obj);
+    return OleCreateFromData(data, iid, renderopt, fmt, client_site, stg, obj);
+}
+
+/******************************************************************************
+ *              OleCreateStaticFromData        [OLE32.@]
+ */
+HRESULT WINAPI OleCreateStaticFromData(IDataObject *data, REFIID iid,
+                                       DWORD renderopt, FORMATETC *fmt,
+                                       IOleClientSite *client_site, IStorage *stg,
+                                       void **obj)
+{
+    FIXME("%p,%s,%08x,%p,%p,%p,%p: semi-stub\n",
+          data, debugstr_guid(iid), renderopt, fmt, client_site, stg, obj);
+    return OleCreateFromData(data, iid, renderopt, fmt, client_site, stg, obj);
+}
 
 /******************************************************************************
  *              OleDuplicateData        [OLE32.@]
index 16ac8d1..5a90e2d 100644 (file)
@@ -43,15 +43,6 @@ HRESULT WINAPI  OleCreateLinkToFile(LPCOLESTR lpszFileName, REFIID riid,
     return E_NOTIMPL;
 }
 
-/******************************************************************************
- *              SetConvertStg        [OLE32.@]
- */
-HRESULT WINAPI SetConvertStg(LPSTORAGE pStg, BOOL fConvert)
-{
-  FIXME("(%p,%x), stub!\n", pStg, fConvert);
-  return E_NOTIMPL;
-}
-
 /******************************************************************************
  *              OleCreateLink        [OLE32.@]
  */
@@ -82,32 +73,6 @@ HGLOBAL WINAPI OleGetIconOfClass(REFCLSID rclsid, LPOLESTR lpszLabel, BOOL fUseT
   return NULL;
 }
 
-
-/******************************************************************************
- *              OleCreateStaticFromData        [OLE32.@]
- */
-HRESULT     WINAPI OleCreateStaticFromData(LPDATAOBJECT pSrcDataObj, REFIID iid,
-                DWORD renderopt, LPFORMATETC pFormatEtc, LPOLECLIENTSITE pClientSite,
-                LPSTORAGE pStg, LPVOID* ppvObj)
-{
-  FIXME("(srcdata=%p, refiid=%s, renderopt=%x, formatetc=%p, client=%p, storage=%p, ppv=%p), stub!\n",
-        pSrcDataObj,debugstr_guid(iid),renderopt,pFormatEtc,pClientSite,pStg,ppvObj );
-  return E_NOTIMPL;
-}
-
-/******************************************************************************
- *              OleCreateLinkFromData        [OLE32.@]
- */
-
-HRESULT WINAPI  OleCreateLinkFromData(LPDATAOBJECT pSrcDataObj, REFIID riid,
-                DWORD renderopt, LPFORMATETC pFormatEtc,
-                LPOLECLIENTSITE pClientSite, LPSTORAGE pStg,
-                LPVOID* ppvObj)
-{
-  FIXME("(not shown), stub!\n");
-  return E_NOTIMPL;
-}
-
 /***********************************************************************
  *           OleRegEnumFormatEtc    [OLE32.@]
  */
index dfcc7c2..9ec09dd 100644 (file)
@@ -27,6 +27,7 @@
 @ stdcall CoGetContextToken(ptr)
 @ stdcall CoGetCurrentLogicalThreadId(ptr)
 @ stdcall CoGetCurrentProcess()
+@ stdcall CoGetDefaultContext(long ptr ptr)
 @ stub CoGetInstanceFromFile      #@ stdcall (ptr ptr ptr long wstr long ptr) return 0,ERR_NOTIMPLEMENTED
 @ stub CoGetInstanceFromIStorage  #@ stdcall (ptr ptr ptr long ptr long ptr) return 0,ERR_NOTIMPLEMENTED
 @ stdcall CoGetInterfaceAndReleaseStream(ptr ptr ptr)
 @ stdcall SetConvertStg(ptr long)
 @ stub SetDocumentBitStg
 @ stdcall SetErrorInfo(long ptr)
+@ stdcall StgConvertPropertyToVariant(ptr long ptr ptr)
+@ stdcall StgConvertVariantToProperty(ptr long ptr ptr long long ptr)
 @ stdcall StgCreateDocfile(wstr long long ptr)
 @ stdcall StgCreateDocfileOnILockBytes(ptr long long ptr)
 @ stdcall StgCreatePropSetStg(ptr long ptr)
index 78e43b1..057a3e3 100644 (file)
@@ -24,11 +24,6 @@ cpp_quote("#if 0    /* ole32_objidl.idl hack */")
 #include "objidl.idl"
 cpp_quote("#endif   /* ole32_objidl.idl hack */")
 
-#ifndef __WIDL__
-#define threading(model)
-#define progid(str)
-#endif
-
 [
     threading(both),
     uuid(00000300-0000-0000-c000-000000000046)
@@ -78,7 +73,6 @@ coclass CompositeMoniker { interface IMoniker; }
 ]
 coclass DfMarshal { interface IMarshal; }
 
-#ifdef __WIDL__
 [
     helpstring("Picture (Metafile)"),
     threading(both),
@@ -94,7 +88,6 @@ coclass Picture_Metafile { interface IPicture; }
     uuid(00000316-0000-0000-c000-000000000046)
 ]
 coclass Picture_Dib { interface IPicture; }
-#endif
 
 [
     threading(both),
@@ -103,13 +96,11 @@ coclass Picture_Dib { interface IPicture; }
 ]
 coclass ClassMoniker { interface IMoniker; }
 
-#ifdef __WIDL__
 [
     threading(both),
     uuid(00000320-0000-0000-c000-000000000046)
 ]
 coclass PSFactoryBuffer { interface IFactoryBuffer; }
-#endif
 
 [
     threading(apartment),
@@ -117,11 +108,9 @@ coclass PSFactoryBuffer { interface IFactoryBuffer; }
 ]
 coclass StdGlobalInterfaceTable { interface IGlobalInterfaceTable; }
 
-#ifdef __WIDL__
 [
     helpstring("Component Categories Manager"),
     threading(both),
     uuid(0002e005-0000-0000-c000-000000000046)
 ]
 coclass StdComponentCategoriesMgr { interface ICatRegister; interface ICatInformation; }
-#endif
index c721829..a3bd881 100644 (file)
 
 #include "oleidl.idl"
 
-#ifdef __WIDL__
 [
     threading(both),
     uuid(00000320-0000-0000-c000-000000000046)
 ]
 coclass PSFactoryBuffer { interface IFactoryBuffer; }
-#endif
index 7a42482..9be195f 100644 (file)
@@ -24,10 +24,8 @@ cpp_quote("#if 0    /* oleaut32_unknwn.idl hack */")
 #include "unknwn.idl"
 cpp_quote("#endif   /* oleaut32_unknwn.idl hack */")
 
-#ifdef __WIDL__
 [
     threading(both),
     uuid(00000320-0000-0000-c000-000000000046)
 ]
 coclass PSFactoryBuffer { interface IFactoryBuffer; }
-#endif
index 6a84681..968456d 100644 (file)
@@ -96,7 +96,7 @@ static HRESULT WINAPI EnumSTATDATA_QueryInterface(IEnumSTATDATA *iface, REFIID r
     if (IsEqualIID(riid, &IID_IUnknown) ||
         IsEqualIID(riid, &IID_IEnumSTATDATA))
     {
-        IUnknown_AddRef(iface);
+        IEnumSTATDATA_AddRef(iface);
         *ppv = iface;
         return S_OK;
     }
index d39be1d..9af162a 100644 (file)
@@ -596,7 +596,7 @@ static HRESULT WINAPI PointerMonikerCF_QueryInterface(LPCLASSFACTORY iface,
     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IClassFactory_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
index c336743..9b57206 100644 (file)
@@ -94,8 +94,11 @@ static inline void get_rpc_endpoint(LPWSTR endpoint, const OXID *oxid)
 
 typedef struct
 {
-    const IRpcChannelBufferVtbl *lpVtbl;
-    LONG                  refs;
+    IRpcChannelBuffer IRpcChannelBuffer_iface;
+    LONG refs;
+
+    DWORD dest_context; /* returned from GetDestCtx */
+    void *dest_context_data; /* returned from GetDestCtx */
 } RpcChannelBuffer;
 
 typedef struct
@@ -105,8 +108,6 @@ typedef struct
     RPC_BINDING_HANDLE     bind; /* handle to the remote server */
     OXID                   oxid; /* apartment in which the channel is valid */
     DWORD                  server_pid; /* id of server process */
-    DWORD                  dest_context; /* returned from GetDestCtx */
-    LPVOID                 dest_context_data; /* returned from GetDestCtx */
     HANDLE                 event; /* cached event handle */
 } ClientRpcChannelBuffer;
 
@@ -459,13 +460,13 @@ void RPC_UnregisterAllChannelHooks(void)
 
 /* RPC Channel Buffer Functions */
 
-static HRESULT WINAPI RpcChannelBuffer_QueryInterface(LPRPCCHANNELBUFFER iface, REFIID riid, LPVOID *ppv)
+static HRESULT WINAPI RpcChannelBuffer_QueryInterface(IRpcChannelBuffer *iface, REFIID riid, LPVOID *ppv)
 {
     *ppv = NULL;
     if (IsEqualIID(riid,&IID_IRpcChannelBuffer) || IsEqualIID(riid,&IID_IUnknown))
     {
         *ppv = iface;
-        IUnknown_AddRef(iface);
+        IRpcChannelBuffer_AddRef(iface);
         return S_OK;
     }
     return E_NOINTERFACE;
@@ -1041,20 +1042,20 @@ static HRESULT WINAPI ClientRpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface
 
     TRACE("(%p,%p)\n", pdwDestContext, ppvDestContext);
 
-    *pdwDestContext = This->dest_context;
-    *ppvDestContext = This->dest_context_data;
+    *pdwDestContext = This->super.dest_context;
+    *ppvDestContext = This->super.dest_context_data;
 
     return S_OK;
 }
 
-static HRESULT WINAPI ServerRpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* pdwDestContext, void** ppvDestContext)
+static HRESULT WINAPI ServerRpcChannelBuffer_GetDestCtx(LPRPCCHANNELBUFFER iface, DWORD* dest_context, void** dest_context_data)
 {
-    WARN("(%p,%p), stub!\n", pdwDestContext, ppvDestContext);
+    RpcChannelBuffer *This = (RpcChannelBuffer *)iface;
 
-    /* FIXME: implement this by storing the dwDestContext and pvDestContext
-     * values passed into IMarshal_MarshalInterface and returning them here */
-    *pdwDestContext = MSHCTX_DIFFERENTMACHINE;
-    *ppvDestContext = NULL;
+    TRACE("(%p,%p)\n", dest_context, dest_context_data);
+
+    *dest_context = This->dest_context;
+    *dest_context_data = This->dest_context_data;
     return S_OK;
 }
 
@@ -1142,30 +1143,32 @@ HRESULT RPC_CreateClientChannel(const OXID *oxid, const IPID *ipid,
         return E_OUTOFMEMORY;
     }
 
-    This->super.lpVtbl = &ClientRpcChannelBufferVtbl;
+    This->super.IRpcChannelBuffer_iface.lpVtbl = &ClientRpcChannelBufferVtbl;
     This->super.refs = 1;
+    This->super.dest_context = dest_context;
+    This->super.dest_context_data = dest_context_data;
     This->bind = bind;
     apartment_getoxid(COM_CurrentApt(), &This->oxid);
     This->server_pid = oxid_info->dwPid;
-    This->dest_context = dest_context;
-    This->dest_context_data = dest_context_data;
     This->event = NULL;
 
-    *chan = (IRpcChannelBuffer*)This;
+    *chan = &This->super.IRpcChannelBuffer_iface;
 
     return S_OK;
 }
 
-HRESULT RPC_CreateServerChannel(IRpcChannelBuffer **chan)
+HRESULT RPC_CreateServerChannel(DWORD dest_context, void *dest_context_data, IRpcChannelBuffer **chan)
 {
     RpcChannelBuffer *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
     if (!This)
         return E_OUTOFMEMORY;
 
-    This->lpVtbl = &ServerRpcChannelBufferVtbl;
+    This->IRpcChannelBuffer_iface.lpVtbl = &ServerRpcChannelBufferVtbl;
     This->refs = 1;
+    This->dest_context = dest_context;
+    This->dest_context_data = dest_context_data;
     
-    *chan = (IRpcChannelBuffer*)This;
+    *chan = &This->IRpcChannelBuffer_iface;
 
     return S_OK;
 }
index 53f57c1..915ecff 100644 (file)
@@ -36,6 +36,9 @@
  *   PropertyStorage_ReadFromStream
  */
 
+#include "config.h"
+#include "wine/port.h"
+
 #include <assert.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include "dictionary.h"
 #include "storage32.h"
 #include "enumx.h"
+#include "oleauto.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(storage);
 
 static inline StorageImpl *impl_from_IPropertySetStorage( IPropertySetStorage *iface )
 {
-    return (StorageImpl *)((char*)iface - FIELD_OFFSET(StorageImpl, base.pssVtbl));
+    return CONTAINING_RECORD(iface, StorageImpl, base.IPropertySetStorage_iface);
 }
 
 /* These are documented in MSDN,
@@ -1030,11 +1034,22 @@ static HRESULT PropertyStorage_ReadDictionary(PropertyStorage_impl *This,
     return hr;
 }
 
+#ifdef __i386__
+#define __thiscall __stdcall
+#else
+#define __thiscall __cdecl
+#endif
+
+static void* __thiscall Allocate_CoTaskMemAlloc(void *userdata, ULONG size)
+{
+    return CoTaskMemAlloc(size);
+}
+
 /* FIXME: there isn't any checking whether the read property extends past the
  * end of the buffer.
  */
-static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This,
PROPVARIANT *prop, const BYTE *data)
+static HRESULT PropertyStorage_ReadProperty(PROPVARIANT *prop, const BYTE *data,
   UINT codepage, void* (__thiscall *allocate)(void *userdata, ULONG size), void *allocate_data)
 {
     HRESULT hr = S_OK;
 
@@ -1078,21 +1093,21 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This,
         DWORD count;
        
         StorageUtl_ReadDWord(data, 0, &count);
-        if (This->codePage == CP_UNICODE && count / 2)
+        if (codepage == CP_UNICODE && count % 2)
         {
             WARN("Unicode string has odd number of bytes\n");
             hr = STG_E_INVALIDHEADER;
         }
         else
         {
-            prop->u.pszVal = CoTaskMemAlloc(count);
+            prop->u.pszVal = allocate(allocate_data, count);
             if (prop->u.pszVal)
             {
                 memcpy(prop->u.pszVal, data + sizeof(DWORD), count);
-                /* This is stored in the code page specified in This->codePage.
+                /* This is stored in the code page specified in codepage.
                  * Don't convert it, the caller will just store it as-is.
                  */
-                if (This->codePage == CP_UNICODE)
+                if (codepage == CP_UNICODE)
                 {
                     /* Make sure it's NULL-terminated */
                     prop->u.pszVal[count / sizeof(WCHAR) - 1] = '\0';
@@ -1111,13 +1126,47 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This,
         }
         break;
     }
+    case VT_BSTR:
+    {
+        DWORD count, wcount;
+
+        StorageUtl_ReadDWord(data, 0, &count);
+        if (codepage == CP_UNICODE && count % 2)
+        {
+            WARN("Unicode string has odd number of bytes\n");
+            hr = STG_E_INVALIDHEADER;
+        }
+        else
+        {
+            if (codepage == CP_UNICODE)
+                wcount = count / 2;
+            else
+                wcount = MultiByteToWideChar(codepage, 0, (LPCSTR)(data + sizeof(DWORD)), count, NULL, 0);
+
+            prop->u.bstrVal = SysAllocStringLen(NULL, wcount); /* FIXME: use allocator? */
+
+            if (prop->u.bstrVal)
+            {
+                if (codepage == CP_UNICODE)
+                    memcpy(prop->u.bstrVal, data + sizeof(DWORD), count);
+                else
+                    MultiByteToWideChar(codepage, 0, (LPCSTR)(data + sizeof(DWORD)), count, prop->u.bstrVal, wcount);
+
+                prop->u.bstrVal[wcount - 1] = '\0';
+                TRACE("Read string value %s\n", debugstr_w(prop->u.bstrVal));
+            }
+            else
+                hr = STG_E_INSUFFICIENTMEMORY;
+        }
+        break;
+    }
     case VT_BLOB:
     {
         DWORD count;
 
         StorageUtl_ReadDWord(data, 0, &count);
         prop->u.blob.cbSize = count;
-        prop->u.blob.pBlobData = CoTaskMemAlloc(count);
+        prop->u.blob.pBlobData = allocate(allocate_data, count);
         if (prop->u.blob.pBlobData)
         {
             memcpy(prop->u.blob.pBlobData, data + sizeof(DWORD), count);
@@ -1132,7 +1181,7 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This,
         DWORD count;
 
         StorageUtl_ReadDWord(data, 0, &count);
-        prop->u.pwszVal = CoTaskMemAlloc(count * sizeof(WCHAR));
+        prop->u.pwszVal = allocate(allocate_data, count * sizeof(WCHAR));
         if (prop->u.pwszVal)
         {
             memcpy(prop->u.pwszVal, data + sizeof(DWORD),
@@ -1159,10 +1208,10 @@ static HRESULT PropertyStorage_ReadProperty(PropertyStorage_impl *This,
             if (len > 8)
             {
                 len -= 8;
-                prop->u.pclipdata = CoTaskMemAlloc(sizeof (CLIPDATA));
+                prop->u.pclipdata = allocate(allocate_data, sizeof (CLIPDATA));
                 prop->u.pclipdata->cbSize = len;
                 prop->u.pclipdata->ulClipFmt = tag;
-                prop->u.pclipdata->pClipData = CoTaskMemAlloc(len - sizeof(prop->u.pclipdata->ulClipFmt));
+                prop->u.pclipdata->pClipData = allocate(allocate_data, len - sizeof(prop->u.pclipdata->ulClipFmt));
                 memcpy(prop->u.pclipdata->pClipData, data+8, len - sizeof(prop->u.pclipdata->ulClipFmt));
             }
             else
@@ -1399,8 +1448,9 @@ static HRESULT PropertyStorage_ReadFromStream(PropertyStorage_impl *This)
                 PROPVARIANT prop;
 
                 PropVariantInit(&prop);
-                if (SUCCEEDED(PropertyStorage_ReadProperty(This, &prop,
-                 buf + idOffset->dwOffset - sizeof(PROPERTYSECTIONHEADER))))
+                if (SUCCEEDED(PropertyStorage_ReadProperty(&prop,
+                 buf + idOffset->dwOffset - sizeof(PROPERTYSECTIONHEADER),
+                 This->codePage, Allocate_CoTaskMemAlloc, NULL)))
                 {
                     TRACE("Read property with ID 0x%08x, type %d\n",
                      idOffset->propid, prop.vt);
@@ -2100,7 +2150,7 @@ static HRESULT WINAPI IPropertySetStorage_fnQueryInterface(
     void** ppvObject)
 {
     StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
-    return IStorage_QueryInterface( (IStorage*)This, riid, ppvObject );
+    return IStorage_QueryInterface( &This->base.IStorage_iface, riid, ppvObject );
 }
 
 /************************************************************************
@@ -2112,7 +2162,7 @@ static ULONG WINAPI IPropertySetStorage_fnAddRef(
     IPropertySetStorage *ppstg)
 {
     StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
-    return IStorage_AddRef( (IStorage*)This );
+    return IStorage_AddRef( &This->base.IStorage_iface );
 }
 
 /************************************************************************
@@ -2124,7 +2174,7 @@ static ULONG WINAPI IPropertySetStorage_fnRelease(
     IPropertySetStorage *ppstg)
 {
     StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
-    return IStorage_Release( (IStorage*)This );
+    return IStorage_Release( &This->base.IStorage_iface );
 }
 
 /************************************************************************
@@ -2173,7 +2223,7 @@ static HRESULT WINAPI IPropertySetStorage_fnCreate(
     if (FAILED(r))
         goto end;
 
-    r = IStorage_CreateStream( (IStorage*)This, name, grfMode, 0, 0, &stm );
+    r = IStorage_CreateStream( &This->base.IStorage_iface, name, grfMode, 0, 0, &stm );
     if (FAILED(r))
         goto end;
 
@@ -2218,7 +2268,7 @@ static HRESULT WINAPI IPropertySetStorage_fnOpen(
     if (FAILED(r))
         goto end;
 
-    r = IStorage_OpenStream((IStorage*) This, name, 0, grfMode, 0, &stm );
+    r = IStorage_OpenStream( &This->base.IStorage_iface, name, 0, grfMode, 0, &stm );
     if (FAILED(r))
         goto end;
 
@@ -2237,7 +2287,6 @@ static HRESULT WINAPI IPropertySetStorage_fnDelete(
     REFFMTID rfmtid)
 {
     StorageImpl *This = impl_from_IPropertySetStorage(ppstg);
-    IStorage *stg = NULL;
     WCHAR name[CCH_MAX_PROPSTG_NAME];
     HRESULT r;
 
@@ -2250,8 +2299,7 @@ static HRESULT WINAPI IPropertySetStorage_fnDelete(
     if (FAILED(r))
         return r;
 
-    stg = (IStorage*) This;
-    return IStorage_DestroyElement(stg, name);
+    return IStorage_DestroyElement(&This->base.IStorage_iface, name);
 }
 
 /************************************************************************
@@ -2321,7 +2369,7 @@ static HRESULT create_EnumSTATPROPSETSTG(
     StorageImpl *This,
     IEnumSTATPROPSETSTG** ppenum)
 {
-    IStorage *stg = (IStorage*) &This->base.lpVtbl;
+    IStorage *stg = &This->base.IStorage_iface;
     IEnumSTATSTG *penum = NULL;
     STATSTG stat;
     ULONG count;
@@ -2338,7 +2386,10 @@ static HRESULT create_EnumSTATPROPSETSTG(
     /* add all the property set elements into a list */
     r = IStorage_EnumElements(stg, 0, NULL, 0, &penum);
     if (FAILED(r))
+    {
+        enumx_Release(enumx);
         return E_OUTOFMEMORY;
+    }
 
     while (1)
     {
@@ -2675,3 +2726,51 @@ HRESULT WINAPI PropStgNameToFmtId(const LPOLESTR str, FMTID *rfmtid)
 end:
     return hr;
 }
+
+#ifdef __i386__  /* thiscall functions are i386-specific */
+
+#define DEFINE_STDCALL_WRAPPER(num,func,args) \
+   __ASM_STDCALL_FUNC(func, args, \
+                   "popl %eax\n\t" \
+                   "popl %ecx\n\t" \
+                   "pushl %eax\n\t" \
+                   "movl (%ecx), %eax\n\t" \
+                   "jmp *(4*(" #num "))(%eax)" )
+
+DEFINE_STDCALL_WRAPPER(0,Allocate_PMemoryAllocator,8)
+extern void* __thiscall Allocate_PMemoryAllocator(void *this, ULONG cbSize);
+
+#else
+
+static void* __thiscall Allocate_PMemoryAllocator(void *this, ULONG cbSize)
+{
+    void* (__thiscall *fn)(void*,ULONG) = **(void***)this;
+    return fn(this, cbSize);
+}
+
+#endif
+
+BOOLEAN WINAPI StgConvertPropertyToVariant(const SERIALIZEDPROPERTYVALUE* prop,
+    USHORT CodePage, PROPVARIANT* pvar, void* pma)
+{
+    HRESULT hr;
+
+    hr = PropertyStorage_ReadProperty(pvar, (const BYTE*)prop, CodePage, Allocate_PMemoryAllocator, pma);
+
+    if (FAILED(hr))
+    {
+        FIXME("should raise C++ exception on failure\n");
+        PropVariantInit(pvar);
+    }
+
+    return 0;
+}
+
+SERIALIZEDPROPERTYVALUE* WINAPI StgConvertVariantToProperty(const PROPVARIANT *pvar,
+    USHORT CodePage, SERIALIZEDPROPERTYVALUE *pprop, ULONG *pcb, PROPID pid,
+    BOOLEAN fReserved, ULONG *pcIndirect)
+{
+    FIXME("%p,%d,%p,%p,%d,%d,%p\n", pvar, CodePage, pprop, pcb, pid, fReserved, pcIndirect);
+
+    return NULL;
+}
index b09ba5b..e9fc0c0 100644 (file)
@@ -57,7 +57,7 @@ static void StgStreamImpl_Destroy(StgStreamImpl* This)
 
   /*
    * Release the reference we are holding on the parent storage.
-   * IStorage_Release((IStorage*)This->parentStorage);
+   * IStorage_Release(&This->parentStorage->IStorage_iface);
    *
    * No, don't do this. Some apps call IStorage_Release without
    * calling IStream_Release first. If we grab a reference the
@@ -74,9 +74,6 @@ static void StgStreamImpl_Destroy(StgStreamImpl* This)
 
   This->parentStorage = 0;
 
-  /*
-   * Finally, free the memory used-up by the class.
-   */
   HeapFree(GetProcessHeap(), 0, This);
 }
 
@@ -89,41 +86,22 @@ static HRESULT WINAPI StgStreamImpl_QueryInterface(
                  REFIID         riid,        /* [in] */
                  void**         ppvObject)   /* [iid_is][out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
-  /*
-   * Perform a sanity check on the parameters.
-   */
   if (ppvObject==0)
     return E_INVALIDARG;
 
-  /*
-   * Initialize the return parameter.
-   */
   *ppvObject = 0;
 
-  /*
-   * Compare the riid with the interface IDs implemented by this object.
-   */
   if (IsEqualIID(&IID_IUnknown, riid) ||
-      IsEqualIID(&IID_IPersist, riid) ||
-      IsEqualIID(&IID_IPersistStream, riid) ||
       IsEqualIID(&IID_ISequentialStream, riid) ||
       IsEqualIID(&IID_IStream, riid))
   {
-    *ppvObject = This;
+    *ppvObject = &This->IStream_iface;
   }
-
-  /*
-   * Check that we obtained an interface.
-   */
-  if ((*ppvObject)==0)
+  else
     return E_NOINTERFACE;
 
-  /*
-   * Query Interface always increases the reference count by one when it is
-   * successful
-   */
   IStream_AddRef(iface);
 
   return S_OK;
@@ -136,7 +114,7 @@ static HRESULT WINAPI StgStreamImpl_QueryInterface(
 static ULONG WINAPI StgStreamImpl_AddRef(
                IStream* iface)
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
   return InterlockedIncrement(&This->ref);
 }
 
@@ -147,7 +125,7 @@ static ULONG WINAPI StgStreamImpl_AddRef(
 static ULONG WINAPI StgStreamImpl_Release(
                IStream* iface)
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   ULONG ref;
 
@@ -179,7 +157,7 @@ static HRESULT WINAPI StgStreamImpl_Read(
                  ULONG          cb,        /* [in] */
                  ULONG*         pcbRead)   /* [out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   ULONG bytesReadBuffer;
   HRESULT res;
@@ -235,7 +213,7 @@ static HRESULT WINAPI StgStreamImpl_Write(
                  ULONG          cb,          /* [in] */
                  ULONG*         pcbWritten)  /* [out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   ULONG bytesWritten = 0;
   HRESULT res;
@@ -316,7 +294,7 @@ static HRESULT WINAPI StgStreamImpl_Seek(
                  DWORD           dwOrigin,         /* [in] */
                  ULARGE_INTEGER* plibNewPosition) /* [out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   ULARGE_INTEGER newPosition;
   DirEntry currentEntry;
@@ -389,7 +367,7 @@ static HRESULT WINAPI StgStreamImpl_SetSize(
                                     IStream*      iface,
                                     ULARGE_INTEGER  libNewSize)   /* [in] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   HRESULT      hr;
 
@@ -441,7 +419,7 @@ static HRESULT WINAPI StgStreamImpl_CopyTo(
                                    ULARGE_INTEGER* pcbRead,      /* [out] */
                                    ULARGE_INTEGER* pcbWritten)   /* [out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
   HRESULT        hr = S_OK;
   BYTE           tmpBuffer[128];
   ULONG          bytesRead, bytesWritten, copySize;
@@ -516,7 +494,7 @@ static HRESULT WINAPI StgStreamImpl_Commit(
                  IStream*      iface,
                  DWORD           grfCommitFlags)  /* [in] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   if (!This->parentStorage)
   {
@@ -547,7 +525,7 @@ static HRESULT WINAPI StgStreamImpl_LockRegion(
                                        ULARGE_INTEGER cb,          /* [in] */
                                        DWORD          dwLockType)  /* [in] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   if (!This->parentStorage)
   {
@@ -565,7 +543,7 @@ static HRESULT WINAPI StgStreamImpl_UnlockRegion(
                                          ULARGE_INTEGER cb,          /* [in] */
                                          DWORD          dwLockType)  /* [in] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   if (!This->parentStorage)
   {
@@ -590,7 +568,7 @@ static HRESULT WINAPI StgStreamImpl_Stat(
                  STATSTG*       pstatstg,     /* [out] */
                  DWORD          grfStatFlag)  /* [in] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
 
   DirEntry     currentEntry;
   HRESULT      hr;
@@ -650,7 +628,7 @@ static HRESULT WINAPI StgStreamImpl_Clone(
                                   IStream*     iface,
                                   IStream**    ppstm) /* [out] */
 {
-  StgStreamImpl* const This=(StgStreamImpl*)iface;
+  StgStreamImpl* This = impl_from_IStream(iface);
   HRESULT hres;
   StgStreamImpl* new_stream;
   LARGE_INTEGER seek_pos;
@@ -672,12 +650,12 @@ static HRESULT WINAPI StgStreamImpl_Clone(
   if (!new_stream)
     return STG_E_INSUFFICIENTMEMORY; /* Currently the only reason for new_stream=0 */
 
-  *ppstm = (IStream*) new_stream;
+  *ppstm = &new_stream->IStream_iface;
   IStream_AddRef(*ppstm);
 
   seek_pos.QuadPart = This->currentPosition.QuadPart;
 
-  hres=StgStreamImpl_Seek (*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
+  hres = IStream_Seek(*ppstm, seek_pos, STREAM_SEEK_SET, NULL);
 
   assert (SUCCEEDED(hres));
 
@@ -687,7 +665,7 @@ static HRESULT WINAPI StgStreamImpl_Clone(
 /*
  * Virtual function table for the StgStreamImpl class.
  */
-static const IStreamVtbl StgStreamImpl_Vtbl =
+static const IStreamVtbl StgStreamVtbl =
 {
     StgStreamImpl_QueryInterface,
     StgStreamImpl_AddRef,
@@ -725,12 +703,12 @@ StgStreamImpl* StgStreamImpl_Construct(
 
   newStream = HeapAlloc(GetProcessHeap(), 0, sizeof(StgStreamImpl));
 
-  if (newStream!=0)
+  if (newStream)
   {
     /*
      * Set-up the virtual function table and reference count.
      */
-    newStream->lpVtbl    = &StgStreamImpl_Vtbl;
+    newStream->IStream_iface.lpVtbl = &StgStreamVtbl;
     newStream->ref       = 0;
 
     newStream->parentStorage = parentStorage;
@@ -739,7 +717,7 @@ StgStreamImpl* StgStreamImpl_Construct(
      * We want to nail-down the reference to the storage in case the
      * stream out-lives the storage in the client application.
      *
-     * -- IStorage_AddRef((IStorage*)newStream->parentStorage);
+     * -- IStorage_AddRef(&newStream->parentStorage->IStorage_iface);
      *
      * No, don't do this. Some apps call IStorage_Release without
      * calling IStream_Release first. If we grab a reference the
index f233b61..f259d24 100644 (file)
@@ -52,6 +52,7 @@
 
 #include "winreg.h"
 #include "wine/wingdi16.h"
+#include "compobj_private.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(storage);
 
@@ -65,7 +66,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(storage);
 static const BYTE STORAGE_magic[8]    ={0xd0,0xcf,0x11,0xe0,0xa1,0xb1,0x1a,0xe1};
 static const BYTE STORAGE_oldmagic[8] ={0xd0,0xcf,0x11,0xe0,0x0e,0x11,0xfc,0x0d};
 
-static const char rootEntryName[] = "Root Entry";
+static inline StorageBaseImpl *impl_from_IStorage( IStorage *iface )
+{
+    return CONTAINING_RECORD(iface, StorageBaseImpl, IStorage_iface);
+}
 
 /****************************************************************************
  * Storage32InternalImpl definitions.
@@ -360,9 +364,9 @@ static HRESULT WINAPI StorageBaseImpl_QueryInterface(
   REFIID             riid,
   void**             ppvObject)
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
 
-  if ( (This==0) || (ppvObject==0) )
+  if (!ppvObject)
     return E_INVALIDARG;
 
   *ppvObject = 0;
@@ -370,14 +374,13 @@ static HRESULT WINAPI StorageBaseImpl_QueryInterface(
   if (IsEqualGUID(&IID_IUnknown, riid) ||
       IsEqualGUID(&IID_IStorage, riid))
   {
-    *ppvObject = This;
+    *ppvObject = &This->IStorage_iface;
   }
   else if (IsEqualGUID(&IID_IPropertySetStorage, riid))
   {
-    *ppvObject = &This->pssVtbl;
+    *ppvObject = &This->IPropertySetStorage_iface;
   }
-
-  if ((*ppvObject)==0)
+  else
     return E_NOINTERFACE;
 
   IStorage_AddRef(iface);
@@ -396,7 +399,7 @@ static HRESULT WINAPI StorageBaseImpl_QueryInterface(
 static ULONG WINAPI StorageBaseImpl_AddRef(
             IStorage* iface)
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   ULONG ref = InterlockedIncrement(&This->ref);
 
   TRACE("(%p) AddRef to %d\n", This, ref);
@@ -415,7 +418,7 @@ static ULONG WINAPI StorageBaseImpl_AddRef(
 static ULONG WINAPI StorageBaseImpl_Release(
       IStorage* iface)
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
 
   ULONG ref = InterlockedDecrement(&This->ref);
 
@@ -449,7 +452,7 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream(
   DWORD            reserved2, /* [in]  */
   IStream**        ppstm)     /* [out] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   StgStreamImpl*    newStream;
   DirEntry          currentEntry;
   DirRef            streamEntryRef;
@@ -524,10 +527,10 @@ static HRESULT WINAPI StorageBaseImpl_OpenStream(
 
     newStream = StgStreamImpl_Construct(This, grfMode, streamEntryRef);
 
-    if (newStream!=0)
+    if (newStream)
     {
       newStream->grfMode = grfMode;
-      *ppstm = (IStream*)newStream;
+      *ppstm = &newStream->IStream_iface;
 
       IStream_AddRef(*ppstm);
 
@@ -564,7 +567,7 @@ static HRESULT WINAPI StorageBaseImpl_OpenStorage(
   DWORD            reserved,      /* [in] */
   IStorage**       ppstg)         /* [out] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   StorageInternalImpl*   newStorage;
   StorageBaseImpl*       newTransactedStorage;
   DirEntry               currentEntry;
@@ -575,7 +578,7 @@ static HRESULT WINAPI StorageBaseImpl_OpenStorage(
        iface, debugstr_w(pwcsName), pstgPriority,
        grfMode, snbExclude, reserved, ppstg);
 
-  if ( (This==0) || (pwcsName==NULL) || (ppstg==0) )
+  if ((pwcsName==NULL) || (ppstg==0) )
   {
     res = E_INVALIDARG;
     goto end;
@@ -661,11 +664,11 @@ static HRESULT WINAPI StorageBaseImpl_OpenStorage(
           goto end;
         }
 
-        *ppstg = (IStorage*)newTransactedStorage;
+        *ppstg = &newTransactedStorage->IStorage_iface;
       }
       else
       {
-        *ppstg = (IStorage*)newStorage;
+        *ppstg = &newStorage->base.IStorage_iface;
       }
 
       list_add_tail(&This->storageHead, &newStorage->ParentListEntry);
@@ -700,13 +703,13 @@ static HRESULT WINAPI StorageBaseImpl_EnumElements(
   DWORD           reserved3, /* [in] */
   IEnumSTATSTG**  ppenum)    /* [out] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   IEnumSTATSTGImpl* newEnum;
 
   TRACE("(%p, %d, %p, %d, %p)\n",
        iface, reserved1, reserved2, reserved3, ppenum);
 
-  if ( (This==0) || (ppenum==0))
+  if (!ppenum)
     return E_INVALIDARG;
 
   if (This->reverted)
@@ -716,7 +719,7 @@ static HRESULT WINAPI StorageBaseImpl_EnumElements(
               This,
               This->storageDirEntry);
 
-  if (newEnum!=0)
+  if (newEnum)
   {
     *ppenum = &newEnum->IEnumSTATSTG_iface;
 
@@ -740,14 +743,14 @@ static HRESULT WINAPI StorageBaseImpl_Stat(
   STATSTG*         pstatstg,     /* [out] */
   DWORD            grfStatFlag)  /* [in] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   DirEntry       currentEntry;
   HRESULT        res = STG_E_UNKNOWN;
 
   TRACE("(%p, %p, %x)\n",
        iface, pstatstg, grfStatFlag);
 
-  if ( (This==0) || (pstatstg==0))
+  if (!pstatstg)
   {
     res = E_INVALIDARG;
     goto end;
@@ -797,7 +800,7 @@ static HRESULT WINAPI StorageBaseImpl_RenameElement(
             const OLECHAR*   pwcsOldName,  /* [in] */
             const OLECHAR*   pwcsNewName)  /* [in] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   DirEntry          currentEntry;
   DirRef            currentEntryRef;
 
@@ -881,7 +884,7 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream(
             DWORD            reserved2, /* [in] */
             IStream**        ppstm)     /* [out] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   StgStreamImpl*    newStream;
   DirEntry          currentEntry, newStreamEntry;
   DirRef            currentEntryRef, newStreamEntryRef;
@@ -1007,10 +1010,9 @@ static HRESULT WINAPI StorageBaseImpl_CreateStream(
    */
   newStream = StgStreamImpl_Construct(This, grfMode, newStreamEntryRef);
 
-  if (newStream != 0)
+  if (newStream)
   {
-    *ppstm = (IStream*)newStream;
-
+    *ppstm = &newStream->IStream_iface;
     IStream_AddRef(*ppstm);
   }
   else
@@ -1033,7 +1035,7 @@ static HRESULT WINAPI StorageBaseImpl_SetClass(
   IStorage*        iface,
   REFCLSID         clsid) /* [in] */
 {
-  StorageBaseImpl *This = (StorageBaseImpl *)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
   HRESULT hRes;
   DirEntry currentEntry;
 
@@ -1079,7 +1081,7 @@ static HRESULT WINAPI StorageBaseImpl_CreateStorage(
   DWORD            reserved2, /* [in] */
   IStorage       **ppstg)   /* [out] */
 {
-  StorageBaseImpl* const This=(StorageBaseImpl*)iface;
+  StorageBaseImpl* This = impl_from_IStorage(iface);
 
   DirEntry         currentEntry;
   DirEntry         newEntry;
@@ -1343,15 +1345,12 @@ static HRESULT StorageImpl_DestroyDirEntry(
   StorageBaseImpl *base,
   DirRef index)
 {
-  HRESULT hr;
   BYTE emptyData[RAW_DIRENTRY_SIZE];
   StorageImpl *storage = (StorageImpl*)base;
 
   memset(emptyData, 0, RAW_DIRENTRY_SIZE);
 
-  hr = StorageImpl_WriteRawDirEntry(storage, index, emptyData);
-
-  return hr;
+  return StorageImpl_WriteRawDirEntry(storage, index, emptyData);
 }
 
 
@@ -1684,11 +1683,19 @@ static HRESULT StorageBaseImpl_CopyChildEntryTo(StorageBaseImpl *This,
        */
       if (hr == S_OK)
       {
-        pstrChild = (IStream*)StgStreamImpl_Construct(This, STGM_READ|STGM_SHARE_EXCLUSIVE, srcEntry);
-        if (pstrChild)
-          IStream_AddRef(pstrChild);
+        StgStreamImpl *streamimpl = StgStreamImpl_Construct(This, STGM_READ|STGM_SHARE_EXCLUSIVE, srcEntry);
+
+        if (streamimpl)
+        {
+          pstrChild = &streamimpl->IStream_iface;
+          if (pstrChild)
+            IStream_AddRef(pstrChild);
+        }
         else
+        {
+          pstrChild = NULL;
           hr = E_OUTOFMEMORY;
+        }
       }
 
       if (hr == S_OK)
@@ -1757,7 +1764,7 @@ static HRESULT WINAPI StorageBaseImpl_CopyTo(
   SNB         snbExclude,   /* [unique][in] */
   IStorage*   pstgDest)     /* [unique][in] */
 {
-  StorageBaseImpl* const This=(StorageBaseImpl*)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
 
   BOOL         skip_storage = FALSE, skip_stream = FALSE;
   int          i;
@@ -1793,15 +1800,15 @@ static HRESULT WINAPI StorageBaseImpl_CopyTo(
 
       if (pstgDestAncestor->lpVtbl == &TransactedSnapshotImpl_Vtbl)
       {
-        TransactedSnapshotImpl *impl = (TransactedSnapshotImpl*) pstgDestAncestor;
+        TransactedSnapshotImpl *snapshot = (TransactedSnapshotImpl*) pstgDestAncestor;
 
-        pstgDestAncestor = (IStorage*)impl->transactedParent;
+        pstgDestAncestor = &snapshot->transactedParent->IStorage_iface;
       }
       else if (pstgDestAncestor->lpVtbl == &Storage32InternalImpl_Vtbl)
       {
-        StorageInternalImpl *impl = (StorageInternalImpl*) pstgDestAncestor;
+        StorageInternalImpl *internal = (StorageInternalImpl*) pstgDestAncestor;
 
-        pstgDestAncestor = (IStorage*)impl->parentStorage;
+        pstgDestAncestor = &internal->parentStorage->IStorage_iface;
       }
       else
         break;
@@ -1864,9 +1871,9 @@ static HRESULT WINAPI StorageImpl_Commit(
   IStorage*   iface,
   DWORD         grfCommitFlags)/* [in] */
 {
-  StorageBaseImpl* const base=(StorageBaseImpl*)iface;
+  StorageBaseImpl* This = impl_from_IStorage(iface);
   TRACE("(%p %d)\n", iface, grfCommitFlags);
-  return StorageBaseImpl_Flush(base);
+  return StorageBaseImpl_Flush(This);
 }
 
 /*************************************************************************
@@ -1896,7 +1903,7 @@ static HRESULT WINAPI StorageBaseImpl_DestroyElement(
   IStorage*     iface,
   const OLECHAR *pwcsName)/* [string][in] */
 {
-  StorageBaseImpl* const This=(StorageBaseImpl*)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
 
   HRESULT           hr = S_OK;
   DirEntry          entryToDelete;
@@ -2069,8 +2076,8 @@ static HRESULT deleteStorageContents(
   /*
    * Open the storage and enumerate it
    */
-  hr = StorageBaseImpl_OpenStorage(
-        (IStorage*)parentStorage,
+  hr = IStorage_OpenStorage(
+        &parentStorage->IStorage_iface,
         entryDataToDelete.name,
         0,
         STGM_WRITE | STGM_SHARE_EXCLUSIVE,
@@ -2146,7 +2153,7 @@ static HRESULT deleteStreamContents(
   size.u.HighPart = 0;
   size.u.LowPart = 0;
 
-  hr = StorageBaseImpl_OpenStream((IStorage*)parentStorage,
+  hr = IStorage_OpenStream(&parentStorage->IStorage_iface,
         entryDataToDelete.name, NULL, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, &pis);
 
   if (hr!=S_OK)
@@ -2202,11 +2209,11 @@ static HRESULT removeFromTree(
   DirRef        parentStorageIndex,
   DirRef        deletedIndex)
 {
-  HRESULT hr                     = S_OK;
   DirEntry   entryToDelete;
   DirEntry   parentEntry;
   DirRef parentEntryRef;
   ULONG typeOfRelation;
+  HRESULT hr;
 
   hr = StorageBaseImpl_ReadDirEntry(This, deletedIndex, &entryToDelete);
 
@@ -2318,7 +2325,7 @@ static HRESULT WINAPI StorageBaseImpl_SetStateBits(
   DWORD         grfStateBits,/* [in] */
   DWORD         grfMask)     /* [in] */
 {
-  StorageBaseImpl* const This = (StorageBaseImpl*)iface;
+  StorageBaseImpl *This = impl_from_IStorage(iface);
 
   if (This->reverted)
     return STG_E_REVERTED;
@@ -2710,8 +2717,8 @@ static HRESULT StorageImpl_Construct(
 
   list_init(&This->base.storageHead);
 
-  This->base.lpVtbl = &Storage32Impl_Vtbl;
-  This->base.pssVtbl = &IPropertySetStorage_Vtbl;
+  This->base.IStorage_iface.lpVtbl = &Storage32Impl_Vtbl;
+  This->base.IPropertySetStorage_iface.lpVtbl = &IPropertySetStorage_Vtbl;
   This->base.baseVtbl = &StorageImpl_BaseVtbl;
   This->base.openFlags = (openFlags & ~STGM_CREATE);
   This->base.ref = 1;
@@ -2867,21 +2874,21 @@ static HRESULT StorageImpl_Construct(
    */
   if (create)
   {
+    static const WCHAR rootentryW[] = {'R','o','o','t',' ','E','n','t','r','y',0};
     DirEntry rootEntry;
     /*
      * Initialize the directory table
      */
     memset(&rootEntry, 0, sizeof(rootEntry));
-    MultiByteToWideChar( CP_ACP, 0, rootEntryName, -1, rootEntry.name,
-                         sizeof(rootEntry.name)/sizeof(WCHAR) );
-    rootEntry.sizeOfNameString = (strlenW(rootEntry.name)+1) * sizeof(WCHAR);
+    strcpyW(rootEntry.name, rootentryW);
+    rootEntry.sizeOfNameString = sizeof(rootentryW);
     rootEntry.stgType          = STGTY_ROOT;
-    rootEntry.leftChild = DIRENTRY_NULL;
-    rootEntry.rightChild     = DIRENTRY_NULL;
+    rootEntry.leftChild        = DIRENTRY_NULL;
+    rootEntry.rightChild       = DIRENTRY_NULL;
     rootEntry.dirRootEntry     = DIRENTRY_NULL;
     rootEntry.startingBlock    = BLOCK_END_OF_CHAIN;
-    rootEntry.size.u.HighPart    = 0;
-    rootEntry.size.u.LowPart     = 0;
+    rootEntry.size.u.HighPart  = 0;
+    rootEntry.size.u.LowPart   = 0;
 
     StorageImpl_WriteDirEntry(This, 0, &rootEntry);
   }
@@ -2929,7 +2936,7 @@ static HRESULT StorageImpl_Construct(
 end:
   if (FAILED(hr))
   {
-    IStorage_Release((IStorage*)This);
+    IStorage_Release(&This->base.IStorage_iface);
     *result = NULL;
   }
   else
@@ -4641,7 +4648,7 @@ static HRESULT WINAPI TransactedSnapshotImpl_Commit(
   IStorage*            iface,
   DWORD                  grfCommitFlags)  /* [in] */
 {
-  TransactedSnapshotImpl* This = (TransactedSnapshotImpl*) iface;
+  TransactedSnapshotImpl* This = (TransactedSnapshotImpl*)impl_from_IStorage(iface);
   TransactedDirEntry *root_entry;
   DirRef i, dir_root_ref;
   DirEntry data;
@@ -4746,7 +4753,7 @@ static HRESULT WINAPI TransactedSnapshotImpl_Commit(
 static HRESULT WINAPI TransactedSnapshotImpl_Revert(
   IStorage*            iface)
 {
-  TransactedSnapshotImpl* This = (TransactedSnapshotImpl*) iface;
+  TransactedSnapshotImpl* This = (TransactedSnapshotImpl*)impl_from_IStorage(iface);
   ULARGE_INTEGER zero;
   ULONG i;
 
@@ -4792,14 +4799,10 @@ static void TransactedSnapshotImpl_Destroy( StorageBaseImpl *iface)
 {
   TransactedSnapshotImpl* This = (TransactedSnapshotImpl*) iface;
 
-  TransactedSnapshotImpl_Revert((IStorage*)iface);
-
-  IStorage_Release((IStorage*)This->transactedParent);
-
-  IStorage_Release((IStorage*)This->scratch);
-
+  IStorage_Revert(&This->base.IStorage_iface);
+  IStorage_Release(&This->transactedParent->IStorage_iface);
+  IStorage_Release(&This->scratch->IStorage_iface);
   HeapFree(GetProcessHeap(), 0, This->entries);
-
   HeapFree(GetProcessHeap(), 0, This);
 }
 
@@ -5083,11 +5086,12 @@ static HRESULT TransactedSnapshotImpl_Construct(StorageBaseImpl *parentStorage,
   *result = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TransactedSnapshotImpl));
   if (*result)
   {
-    (*result)->base.lpVtbl = &TransactedSnapshotImpl_Vtbl;
+    IStorage *scratch;
 
-    /* This is OK because the property set storage functions use the IStorage functions. */
-    (*result)->base.pssVtbl = parentStorage->pssVtbl;
+    (*result)->base.IStorage_iface.lpVtbl = &TransactedSnapshotImpl_Vtbl;
 
+    /* This is OK because the property set storage functions use the IStorage functions. */
+    (*result)->base.IPropertySetStorage_iface.lpVtbl = parentStorage->IPropertySetStorage_iface.lpVtbl;
     (*result)->base.baseVtbl = &TransactedSnapshotImpl_BaseVtbl;
 
     list_init(&(*result)->base.strmHead);
@@ -5100,16 +5104,15 @@ static HRESULT TransactedSnapshotImpl_Construct(StorageBaseImpl *parentStorage,
 
     /* Create a new temporary storage to act as the scratch file. */
     hr = StgCreateDocfile(NULL, STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_DELETEONRELEASE,
-        0, (IStorage**)&(*result)->scratch);
+        0, &scratch);
+    (*result)->scratch = impl_from_IStorage(scratch);
 
     if (SUCCEEDED(hr))
     {
         ULONG num_entries = 20;
 
         (*result)->entries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TransactedDirEntry) * num_entries);
-
         (*result)->entries_size = num_entries;
-
         (*result)->firstFreeEntry = 0;
 
         if ((*result)->entries)
@@ -5123,7 +5126,7 @@ static HRESULT TransactedSnapshotImpl_Construct(StorageBaseImpl *parentStorage,
         }
         else
         {
-            IStorage_Release((IStorage*)(*result)->scratch);
+            IStorage_Release(scratch);
 
             hr = E_OUTOFMEMORY;
         }
@@ -5172,7 +5175,7 @@ static HRESULT Storage_Construct(
   {
     hr = Storage_ConstructTransacted(&newStorage->base, &newTransactedStorage);
     if (FAILED(hr))
-      IStorage_Release((IStorage*)newStorage);
+      IStorage_Release(&newStorage->base.IStorage_iface);
     else
       *result = newTransactedStorage;
   }
@@ -5305,9 +5308,9 @@ static HRESULT WINAPI StorageInternalImpl_Commit(
   IStorage*            iface,
   DWORD                  grfCommitFlags)  /* [in] */
 {
-  StorageBaseImpl* base = (StorageBaseImpl*) iface;
+  StorageBaseImpl* This = impl_from_IStorage(iface);
   TRACE("(%p,%x)\n", iface, grfCommitFlags);
-  return StorageBaseImpl_Flush(base);
+  return StorageBaseImpl_Flush(This);
 }
 
 /******************************************************************************
@@ -5324,7 +5327,7 @@ static HRESULT WINAPI StorageInternalImpl_Revert(
 
 static void IEnumSTATSTGImpl_Destroy(IEnumSTATSTGImpl* This)
 {
-  IStorage_Release((IStorage*)This->parentStorage);
+  IStorage_Release(&This->parentStorage->IStorage_iface);
   HeapFree(GetProcessHeap(), 0, This);
 }
 
@@ -5608,7 +5611,7 @@ static IEnumSTATSTGImpl* IEnumSTATSTGImpl_Construct(
      * enumeration out-lives the storage in the client application.
      */
     newEnumeration->parentStorage = parentStorage;
-    IStorage_AddRef((IStorage*)newEnumeration->parentStorage);
+    IStorage_AddRef(&newEnumeration->parentStorage->IStorage_iface);
 
     newEnumeration->storageDirEntry   = storageDirEntry;
 
@@ -5684,8 +5687,8 @@ static StorageInternalImpl* StorageInternalImpl_Construct(
     /*
      * Initialize the virtual function table.
      */
-    newStorage->base.lpVtbl = &Storage32InternalImpl_Vtbl;
-    newStorage->base.pssVtbl = &IPropertySetStorage_Vtbl;
+    newStorage->base.IStorage_iface.lpVtbl = &Storage32InternalImpl_Vtbl;
+    newStorage->base.IPropertySetStorage_iface.lpVtbl = &IPropertySetStorage_Vtbl;
     newStorage->base.baseVtbl = &StorageInternalImpl_BaseVtbl;
     newStorage->base.openFlags = (openFlags & ~STGM_CREATE);
 
@@ -7396,9 +7399,8 @@ static HRESULT create_storagefile(
     goto end;
   }
 
-  hr = IStorage_QueryInterface((IStorage*)newStorage, riid, ppstgOpen);
-
-  IStorage_Release((IStorage*)newStorage);
+  hr = IStorage_QueryInterface(&newStorage->IStorage_iface, riid, ppstgOpen);
+  IStorage_Release(&newStorage->IStorage_iface);
 
 end:
   TRACE("<-- %p  r = %08x\n", *ppstgOpen, hr);
@@ -7488,17 +7490,13 @@ HRESULT WINAPI StgCreateStorageEx(const WCHAR* pwcsName, DWORD grfMode, DWORD st
  *              StgCreatePropSetStg       [OLE32.@]
  */
 HRESULT WINAPI StgCreatePropSetStg(IStorage *pstg, DWORD reserved,
- IPropertySetStorage **ppPropSetStg)
+ IPropertySetStorage **propset)
 {
-    HRESULT hr;
-
-    TRACE("(%p, 0x%x, %p)\n", pstg, reserved, ppPropSetStg);
+    TRACE("(%p, 0x%x, %p)\n", pstg, reserved, propset);
     if (reserved)
-        hr = STG_E_INVALIDPARAMETER;
-    else
-        hr = StorageBaseImpl_QueryInterface(pstg, &IID_IPropertySetStorage,
-         (void**)ppPropSetStg);
-    return hr;
+        return STG_E_INVALIDPARAMETER;
+
+    return IStorage_QueryInterface(pstg, &IID_IPropertySetStorage, (void**)propset);
 }
 
 /******************************************************************************
@@ -7715,10 +7713,7 @@ HRESULT WINAPI StgOpenStorage(
     goto end;
   }
 
-  /*
-   * Get an "out" pointer for the caller.
-   */
-  *ppstgOpen = (IStorage*)newStorage;
+  *ppstgOpen = &newStorage->IStorage_iface;
 
 end:
   TRACE("<-- %08x, IStorage %p\n", hr, ppstgOpen ? *ppstgOpen : NULL);
@@ -7758,10 +7753,7 @@ HRESULT WINAPI StgCreateDocfileOnILockBytes(
     return hr;
   }
 
-  /*
-   * Get an "out" pointer for the caller.
-   */
-  *ppstgOpen = (IStorage*)newStorage;
+  *ppstgOpen = &newStorage->IStorage_iface;
 
   return hr;
 }
@@ -7806,10 +7798,7 @@ HRESULT WINAPI StgOpenStorageOnILockBytes(
     return hr;
   }
 
-  /*
-   * Get an "out" pointer for the caller.
-   */
-  *ppstgOpen = (IStorage*)newStorage;
+  *ppstgOpen = &newStorage->IStorage_iface;
 
   return hr;
 }
@@ -7868,17 +7857,13 @@ HRESULT WINAPI StgIsStorageILockBytes(ILockBytes *plkbyt)
  */
 HRESULT WINAPI WriteClassStg(IStorage* pStg, REFCLSID rclsid)
 {
-  HRESULT hRes;
-
   if(!pStg)
     return E_INVALIDARG;
 
   if(!rclsid)
     return STG_E_INVALIDPOINTER;
 
-  hRes = IStorage_SetClass(pStg, rclsid);
-
-  return hRes;
+  return IStorage_SetClass(pStg, rclsid);
 }
 
 /***********************************************************************
@@ -8536,18 +8521,18 @@ static DWORD OLECONVERT_WriteOLE20ToBuffer(LPSTORAGE pStorage, BYTE **pData)
 }
 
 /*************************************************************************
- * OLECONVERT_CreateOleStream [Internal]
+ * STORAGE_CreateOleStream [Internal]
  *
  * Creates the "\001OLE" stream in the IStorage if necessary.
  *
  * PARAMS
- *     pStorage     [I] Dest storage to create the stream in
+ *     storage     [I] Dest storage to create the stream in
+ *     flags       [I] flags to be set for newly created stream
  *
  * RETURNS
- *     Nothing
+ *     HRESULT return value
  *
  * NOTES
- *     This function is used by OleConvertOLESTREAMToIStorage only.
  *
  *     This stream is still unknown, MS Word seems to have extra data
  *     but since the data is stored in the OLESTREAM there should be
@@ -8555,28 +8540,36 @@ static DWORD OLECONVERT_WriteOLE20ToBuffer(LPSTORAGE pStorage, BYTE **pData)
  *     deleted it will create it with this default data.
  *
  */
-void OLECONVERT_CreateOleStream(LPSTORAGE pStorage)
+HRESULT STORAGE_CreateOleStream(IStorage *storage, DWORD flags)
 {
-    HRESULT hRes;
-    IStream *pStream;
-    static const WCHAR wstrStreamName[] = {1,'O', 'l', 'e', 0};
-    BYTE pOleStreamHeader [] =
+    static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
+    static const DWORD version_magic = 0x02000001;
+    IStream *stream;
+    HRESULT hr;
+
+    hr = IStorage_CreateStream(storage, stream_1oleW, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stream);
+    if (hr == S_OK)
     {
-        0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-        0x00, 0x00, 0x00, 0x00
-    };
+        struct empty_1ole_stream {
+            DWORD version_magic;
+            DWORD flags;
+            DWORD update_options;
+            DWORD reserved;
+            DWORD mon_stream_size;
+        };
+        struct empty_1ole_stream stream_data;
 
-    /* Create stream if not present */
-    hRes = IStorage_CreateStream(pStorage, wstrStreamName,
-        STGM_WRITE  | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream );
+        stream_data.version_magic = version_magic;
+        stream_data.flags = flags;
+        stream_data.update_options = 0;
+        stream_data.reserved = 0;
+        stream_data.mon_stream_size = 0;
 
-    if(hRes == S_OK)
-    {
-        /* Write default Data */
-        hRes = IStream_Write(pStream, pOleStreamHeader, sizeof(pOleStreamHeader), NULL);
-        IStream_Release(pStream);
+        hr = IStream_Write(stream, &stream_data, sizeof(stream_data), NULL);
+        IStream_Release(stream);
     }
+
+    return hr;
 }
 
 /* write a string to a stream, preceded by its length */
@@ -8777,13 +8770,17 @@ HRESULT WINAPI ReadFmtUserTypeStg (LPSTORAGE pstg, CLIPFORMAT* pcf, LPOLESTR* lp
     /* ok, success... now we just need to store what we found */
     if( pcf )
         *pcf = RegisterClipboardFormatW( szOleTypeName );
-    CoTaskMemFree( szOleTypeName );
 
     if( lplpszUserType )
+    {
         *lplpszUserType = szCLSIDName;
-    CoTaskMemFree( szProgIDName );
+        szCLSIDName = NULL;
+    }
 
 end:
+    CoTaskMemFree( szCLSIDName );
+    CoTaskMemFree( szOleTypeName );
+    CoTaskMemFree( szProgIDName );
     IStream_Release( stm );
 
     return r;
@@ -8854,7 +8851,7 @@ HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName
             HKEY hKey;
             LONG hErr;
             /* Get the CLSID Default Name from the Registry */
-            hErr = RegOpenKeyA(HKEY_CLASSES_ROOT, IStorageCompObj.strProgIDName, &hKey);
+            hErr = open_classes_key(HKEY_CLASSES_ROOT, bufferW, MAXIMUM_ALLOWED, &hKey);
             if(hErr == ERROR_SUCCESS)
             {
                 char strTemp[OLESTREAM_MAX_STR_LEN];
@@ -9083,6 +9080,7 @@ static HRESULT OLECONVERT_GetOLE10ProgID(LPSTORAGE pStorage, char *strProgID, DW
         if(hRes == S_OK)
         {
             *dwSize = WideCharToMultiByte(CP_ACP, 0, wstrProgID, -1, strProgID, *dwSize, NULL, FALSE);
+            CoTaskMemFree(wstrProgID);
         }
 
     }
@@ -9307,7 +9305,7 @@ HRESULT WINAPI OleConvertOLESTREAMToIStorage (
         if(hRes == S_OK)
         {
             /*Create the Ole Stream if necessary */
-            OLECONVERT_CreateOleStream(pstg);
+            STORAGE_CreateOleStream(pstg, 0);
         }
     }
 
@@ -9393,12 +9391,93 @@ HRESULT WINAPI OleConvertIStorageToOLESTREAM (
     return hRes;
 }
 
+enum stream_1ole_flags {
+    OleStream_LinkedObject = 0x00000001,
+    OleStream_Convert      = 0x00000004
+};
+
 /***********************************************************************
  *             GetConvertStg (OLE32.@)
  */
-HRESULT WINAPI GetConvertStg(IStorage *stg) {
-    FIXME("unimplemented stub!\n");
-    return E_FAIL;
+HRESULT WINAPI GetConvertStg(IStorage *stg)
+{
+    static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
+    static const DWORD version_magic = 0x02000001;
+    DWORD header[2];
+    IStream *stream;
+    HRESULT hr;
+
+    TRACE("%p\n", stg);
+
+    if (!stg) return E_INVALIDARG;
+
+    hr = IStorage_OpenStream(stg, stream_1oleW, NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &stream);
+    if (FAILED(hr)) return hr;
+
+    hr = IStream_Read(stream, header, sizeof(header), NULL);
+    IStream_Release(stream);
+    if (FAILED(hr)) return hr;
+
+    if (header[0] != version_magic)
+    {
+        ERR("got wrong version magic for 1Ole stream, 0x%08x\n", header[0]);
+        return E_FAIL;
+    }
+
+    return header[1] & OleStream_Convert ? S_OK : S_FALSE;
+}
+
+/***********************************************************************
+ *             SetConvertStg (OLE32.@)
+ */
+HRESULT WINAPI SetConvertStg(IStorage *storage, BOOL convert)
+{
+    DWORD flags = convert ? OleStream_Convert : 0;
+    HRESULT hr;
+
+    TRACE("(%p, %d)\n", storage, convert);
+
+    hr = STORAGE_CreateOleStream(storage, flags);
+    if (hr == STG_E_FILEALREADYEXISTS)
+    {
+        static const WCHAR stream_1oleW[] = {1,'O','l','e',0};
+        IStream *stream;
+        DWORD header[2];
+
+        hr = IStorage_OpenStream(storage, stream_1oleW, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &stream);
+        if (FAILED(hr)) return hr;
+
+        hr = IStream_Read(stream, header, sizeof(header), NULL);
+        if (FAILED(hr))
+        {
+            IStream_Release(stream);
+            return hr;
+        }
+
+        /* update flag if differs */
+        if ((header[1] ^ flags) & OleStream_Convert)
+        {
+            LARGE_INTEGER pos;
+
+            if (header[1] & OleStream_Convert)
+                flags = header[1] & ~OleStream_Convert;
+            else
+                flags = header[1] |  OleStream_Convert;
+
+            pos.QuadPart = sizeof(DWORD);
+            hr = IStream_Seek(stream, pos, STREAM_SEEK_SET, NULL);
+            if (FAILED(hr))
+            {
+                IStream_Release(stream);
+                return hr;
+            }
+
+            hr = IStream_Write(stream, &flags, sizeof(flags), NULL);
+        }
+        IStream_Release(stream);
+    }
+
+    return hr;
 }
 
 /******************************************************************************
@@ -9499,7 +9578,7 @@ HRESULT WINAPI ReadClassStm(IStream *pStm,CLSID *pclsid)
     /* clear the output args */
     *pclsid = CLSID_NULL;
 
-    res = IStream_Read(pStm,(void*)pclsid,sizeof(CLSID),&nbByte);
+    res = IStream_Read(pStm, pclsid, sizeof(CLSID), &nbByte);
 
     if (FAILED(res))
         return res;
index 938bf7b..f2061f3 100644 (file)
@@ -160,25 +160,24 @@ HRESULT FileLockBytesImpl_Construct(HANDLE hFile, DWORD openFlags, LPCWSTR pwcsN
  * Ole Convert support
  */
 
-void OLECONVERT_CreateOleStream(LPSTORAGE pStorage) DECLSPEC_HIDDEN;
+HRESULT STORAGE_CreateOleStream(IStorage*, DWORD) DECLSPEC_HIDDEN;
 HRESULT OLECONVERT_CreateCompObjStream(LPSTORAGE pStorage, LPCSTR strOleTypeName) DECLSPEC_HIDDEN;
 
 
 /****************************************************************************
- * Storage32BaseImpl definitions.
+ * StorageBaseImpl definitions.
  *
  * This structure defines the base information contained in all implementations
- * of IStorage32 contained in this file storage implementation.
+ * of IStorage contained in this file storage implementation.
  *
- * In OOP terms, this is the base class for all the IStorage32 implementations
+ * In OOP terms, this is the base class for all the IStorage implementations
  * contained in this file.
  */
 struct StorageBaseImpl
 {
-  const IStorageVtbl *lpVtbl;    /* Needs to be the first item in the struct
-                           * since we want to cast this in a Storage32 pointer */
-
-  const IPropertySetStorageVtbl *pssVtbl; /* interface for adding a properties stream */
+  IStorage IStorage_iface;
+  IPropertySetStorage IPropertySetStorage_iface; /* interface for adding a properties stream */
+  LONG ref;
 
   /*
    * Stream tracking list
@@ -191,11 +190,6 @@ struct StorageBaseImpl
    */
   struct list storageHead;
 
-  /*
-   * Reference count of this object
-   */
-  LONG ref;
-
   /*
    * TRUE if this object has been invalidated
    */
@@ -418,25 +412,19 @@ SmallBlockChainStream* Storage32Impl_BigBlocksToSmallBlocks(
 /****************************************************************************
  * StgStreamImpl definitions.
  *
- * This class implements the IStream32 interface and represents a stream
+ * This class implements the IStream interface and represents a stream
  * located inside a storage object.
  */
 struct StgStreamImpl
 {
-  const IStreamVtbl *lpVtbl;  /* Needs to be the first item in the struct
-                        * since we want to cast this to an IStream pointer */
+  IStream IStream_iface;
+  LONG ref;
 
   /*
    * We are an entry in the storage object's stream handler list
    */
-
   struct list StrmListEntry;
 
-  /*
-   * Reference count
-   */
-  LONG              ref;
-
   /*
    * Storage that is the parent(owner) of the stream
    */
@@ -458,6 +446,11 @@ struct StgStreamImpl
   ULARGE_INTEGER     currentPosition;
 };
 
+static inline StgStreamImpl *impl_from_IStream( IStream *iface )
+{
+    return CONTAINING_RECORD(iface, StgStreamImpl, IStream_iface);
+}
+
 /*
  * Method definition for the StgStreamImpl class.
  */
index f5a6ee8..e7018b9 100644 (file)
@@ -67,7 +67,8 @@ static inline HRESULT generate_ipid(struct stub_manager *m, IPID *ipid)
 }
 
 /* registers a new interface stub COM object with the stub manager and returns registration record */
-struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, MSHLFLAGS flags)
+struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *sb, IUnknown *iptr, REFIID iid, DWORD dest_context,
+    void *dest_context_data, MSHLFLAGS flags)
 {
     struct ifstub *stub;
     HRESULT hr;
@@ -78,7 +79,7 @@ struct ifstub *stub_manager_new_ifstub(struct stub_manager *m, IRpcStubBuffer *s
     stub = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct ifstub));
     if (!stub) return NULL;
 
-    hr = RPC_CreateServerChannel(&stub->chan);
+    hr = RPC_CreateServerChannel(dest_context, dest_context_data, &stub->chan);
     if (hr != S_OK)
     {
         HeapFree(GetProcessHeap(), 0, stub);
@@ -119,7 +120,7 @@ static void stub_manager_delete_ifstub(struct stub_manager *m, struct ifstub *if
 
     RPC_UnregisterInterface(&ifstub->iid);
 
-    if (ifstub->stubbuffer) IUnknown_Release(ifstub->stubbuffer);
+    if (ifstub->stubbuffer) IRpcStubBuffer_Release(ifstub->stubbuffer);
     IUnknown_Release(ifstub->iface);
     IRpcChannelBuffer_Release(ifstub->chan);
 
@@ -666,7 +667,7 @@ static HRESULT WINAPI RemUnknown_RemQueryInterface(IRemUnknown *iface,
     for (i = 0; i < cIids; i++)
     {
         HRESULT hrobj = marshal_object(apt, &(*ppQIResults)[i].std, &iids[i],
-                                       stubmgr->object, MSHLFLAGS_NORMAL);
+                                       stubmgr->object, MSHCTX_DIFFERENTMACHINE, NULL, MSHLFLAGS_NORMAL);
         if (hrobj == S_OK)
             successful_qis++;
         (*ppQIResults)[i].hResult = hrobj;
@@ -775,7 +776,7 @@ HRESULT start_apartment_remote_unknown(void)
         {
             STDOBJREF stdobjref; /* dummy - not used */
             /* register it with the stub manager */
-            hr = marshal_object(apt, &stdobjref, &IID_IRemUnknown, (IUnknown *)pRemUnknown, MSHLFLAGS_NORMAL|MSHLFLAGSP_REMUNKNOWN);
+            hr = marshal_object(apt, &stdobjref, &IID_IRemUnknown, (IUnknown *)pRemUnknown, MSHCTX_DIFFERENTMACHINE, NULL, MSHLFLAGS_NORMAL|MSHLFLAGSP_REMUNKNOWN);
             /* release our reference to the object as the stub manager will manage the life cycle for us */
             IRemUnknown_Release(pRemUnknown);
             if (hr == S_OK)
index 8f5feef..d1f56c7 100644 (file)
@@ -74,9 +74,9 @@ static const char* debugstr_user_flags(ULONG *pFlags)
     }
 
     if (HIWORD(*pFlags) == NDR_LOCAL_DATA_REPRESENTATION)
-        return wine_dbg_sprintf("MAKELONG(NDR_LOCAL_REPRESENTATION, %s)", loword);
+        return wine_dbg_sprintf("MAKELONG(%s, NDR_LOCAL_DATA_REPRESENTATION)", loword);
     else
-        return wine_dbg_sprintf("MAKELONG(0x%04x, %s)", HIWORD(*pFlags), loword);
+        return wine_dbg_sprintf("MAKELONG(%s, 0x%04x)", loword, HIWORD(*pFlags));
 }
 
 /******************************************************************************
index e2da625..fbe80d8 100644 (file)
@@ -201,7 +201,7 @@ interface IPropertyStorage : IUnknown
     [case(VT_BYREF|VT_DISPATCH)]          IDispatch **ppdispVal;
     [case(VT_BYREF|VT_ARRAY)]             LPSAFEARRAY *pparray;
     [case(VT_BYREF|VT_VARIANT)]           PROPVARIANT *pvarVal;
-    } DUMMYUNIONNAME;
+    };
   };
 
   typedef struct tagPROPVARIANT *LPPROPVARIANT;
@@ -431,6 +431,10 @@ interface IEnumSTATPROPSETSTG : IUnknown
     [out] IEnumSTATPROPSETSTG **ppenum);
 }
 
+typedef struct SERIALIZEDPROPERTYVALUE {
+    DWORD dwType;
+    BYTE rgb[1];
+} SERIALIZEDPROPERTYVALUE;
 
 cpp_quote("HRESULT WINAPI FreePropVariantArray(ULONG,PROPVARIANT*);")
 cpp_quote("HRESULT WINAPI PropVariantClear(PROPVARIANT*);")
index 012a512..4328a04 100644 (file)
@@ -130,7 +130,7 @@ reactos/dll/win32/ntprint         # Synced to Wine-1.5.4
 reactos/dll/win32/objsel          # Synced to Wine-1.5.19
 reactos/dll/win32/odbc32          # Out of sync. Depends on port of Linux ODBC.
 reactos/dll/win32/odbccp32        # Synced to Wine-1.5.19
-reactos/dll/win32/ole32           # Synced to Wine-1.5.4
+reactos/dll/win32/ole32           # Synced to Wine-1.5.19
 reactos/dll/win32/oleacc          # Autosync
 reactos/dll/win32/oleaut32        # Synced to Wine-1.5.19
 reactos/dll/win32/olecli32        # Synced to Wine-1.5.19