0

I have inherited a Microsoft Visual C++ COM project which is a dependency of a core C# application I work with. When recompiling the project and regenerating the interop DLL (using tlbimp), several methods in my library that take in an OLE_HANDLE change their signature from the previous version of my interop DLL.

I wasn't around when the previous interop was generated, but it was almost certainly compiled under VS2005 on Windows Server 2003 / Windows XP. My workstation is now Windows 7 using Visual Studio 2010 (C++ Visual Studio Compiler version 16.00.40219.01 for x64).

This is the generated C# interface for the original and new DLL (using ILSpy):

New Interface (second parameter is marshaled using the ComAliasName attribute & as int):

[TypeLibFunc(64)]
[MethodImpl(MethodImplOptions.InternalCall)]
public virtual extern void GetSequence([MarshalAs(UnmanagedType.Interface)] [In] INameValueArray nvArray, [ComAliasName("stdole.OLE_HANDLE")] [In] int nvSequence);

Old Interface (second parameter is uint):

[TypeLibFunc(64)]
[MethodImpl(MethodImplOptions.InternalCall)]
public virtual extern void GetSequence([MarshalAs(UnmanagedType.Interface)] [In] INameValueArray nvArray, [In] uint nvSequence);

As far as I can see, the input IDL file hasn't changed and there don't seem to be any #includes / conditional statements that would affect the definition of an OLE_HANDLE.

Whenever the methods in question are invoked, an AccessViolationException is thrown.

Does anyone have any ideas why the generated interface may have changed (not sure if any changes in MIDL/TLBIMP would result in this behaviour) or how I might start to debug this further?

Header:

virtual HRESULT STDMETHODCALLTYPE GetSequence(INameValueArray *nvArray, OLE_HANDLE *nvSequence);

C++ source for method:

HRESULT MyNamespace::GetSequence(INameValueArray *nvArray, OLE_HANDLE *nvSequence)
{
    if(!nvArray || !nvSequence)
        return E_POINTER;
    (*nvSequence) = (OLE_HANDLE) (((CNameValueArray *)nvArray)->GetSeq());
    return S_OK;
}
4

0 回答 0