CodefoundryDE / LegacyWrapper

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
MIT License
79 stars 20 forks source link

How to call a ref string function? #18

Open wdstest opened 5 years ago

wdstest commented 5 years ago

When the native signature is int MyFunction(BSTR * pszVerificationId)

With PInvoke I can do something like

[System.Runtime.InteropServices.DllImportAttribute("TestDLL", EntryPoint = "MyFunction", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static extern int MyFunction([MarshalAsAttribute(UnmanagedType.BStr)] ref string test);

With LegacyWrapper I don't know how to get it to work

[LegacyDllImport("TestDLL.dll")]
public interface IUser32Dll : IDisposable
{
    [LegacyDllMethod(CallingConvention = CallingConvention.StdCall)]
    int MyFunction([MarshalAs(UnmanagedType.BStr)]ref String test);
}

But when I call it with

using (var client = WrapperProxyFactory<IUser32Dll>.GetInstance(configuration))
{
    client.MyFunction(ref test);
}

I get System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.'