I am quite new to PInvoke and calling COM functions from C#.
I have managed so far to call some unmanaged functions ib my C++ dll from my C# code but at the moment I am having trouble with one particular function.
I have a sample of the function being correctly defined in some VB6 code below.
Declare Sub GetReplyData3 Lib "WfRelay.dll" (ByVal S As Variant, ByVal P As Long, N As Currency)
I am able to call the COM function from the VB 6 code using this declaration.
The VB code calls the function and passes it a fixed length string as the variant, a long and a currency.
I have to call this function from C# though and i think it may be the first parameter that I am having my troubles with.
I call it as seen below:
I believe that I am Marshalling third parameter the Currency correctly.
[DllImport("C:\\Program Files\\Microsoft Outlook\\OFFICE11\\WfRelay.dll", CallingConvention = CallingConvention.StdCall, ExactSpelling = true)]
public static extern void GetReplyData3(object severReply, int P, [MarshalAs(UnmanagedType.Currency)] decimal N);
I think it is in the first parameter I think I have my issue. I am passing an object to the variant at the moment. I have read this is the correct way of talking to a variant from .Net and have done so successfully for other functions.
This variant though is manipulated by the function and this is why I think I have the issue.
I have also tried sending a StringBuilder to the function as the Variant is sent as a fixed length string in the VB6 code.
This also would not work though.
The error message that I get is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.".
I have also tried sending various string types and fixed length character arrays but all to no avail.
I would really appreciate it if you could help me out with this.