help with pinvoke and variant return type

Announcements and discussion for PInvoke

help with pinvoke and variant return type

Postby fhanggi » Mon Mar 15, 2010 11:30 pm

Could anyone please help me write a pinvoke statement for this function?

[id(0x60030004)]
HRESULT AFAccountPayment(
[in] VARIANT coForm,
[in, out, optional] BSTR* billlist,
[out, retval] VARIANT* );

I have tried a few things but it's not working. I don't know how to code the VARIAN* retval properly.
Mostly i get an error: PInvoke restriction: cannot return variants.

Here is what i have tried so far.
<DllImport("c:\\windows\\system32\\nctk.dll")> _
Public Shared Function AFAccountPayment(ByVal coForm As Object, Optional ByRef billList As String = "") As Object
End Function

<DllImport("c:\\windows\\system32\\nctk.dll")> _
Public Shared Function AFAccountPayment(<Out(), MarshalAs(UnmanagedType.Struct)> ByVal coForm As Object, <[In](), [Out](), MarshalAs(UnmanagedType.VBByRefStr)> Optional ByRef billList As String = Nothing) As Object
End Function

Thank you for any help.
fhanggi
 
Posts: 1
Joined: Mon Mar 15, 2010 11:17 pm

Postby Paul.Martin » Tue Apr 13, 2010 2:18 pm

The best thing I can think of suggesting (without knowing what the VARIANT* will actually be pointing to and if it will be marshallable) is changing the semantics of the PInvoke call. So you could try something like:

<DllImport("c:\\windows\\system32\\nctk.dll")> _
Public Shared Function AFAccountPayment(<Out(), MarshalAs(UnmanagedType.Struct)> ByVal coForm As Object, <[In](), [Out](), MarshalAs(UnmanagedType.VBByRefStr)> Optional ByRef billList As String = Nothing, <Out(), MarshalAs(UnmanagedType.Struct)> ByRef varRet As Object) As IntPtr
End Function
Paul.Martin
 
Posts: 83
Joined: Wed Feb 03, 2010 11:20 am
Location: Cambridgeshire


Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests

cron