I have a VB6 application that uses a C# compiled Dll. I have been successfull in making this work by means of COM. But my problem is that I have a Variant array with String and Double data types inside it. I need to pass this array to my C# Dll, which is receiving the array as an Object. So, all I need to do is to convert the Variant array into an Object array "understandable" by C#. Anyone has any clue on it?
This should do the trick
ArrayList a = new ArrayList(YourObjectArrayHere);
This has to be done right from C# side of things; if it's not, then there isn't much you can do from VB6. That said, by default, a method declared like this:
void Foo(object[] a);
will be seen from VB6 as taking an array of Variant
(or, on IDL level, as SAFEARRAY(VARIANT)
).
If it doesn't work that way for you, then there's something wrong with your C# declarations - please post them so they may be reviewed.
object[] System.Runtime.InteropServices.Marshal.GetObjectsForNativeVariants(IntPtr aSrcNativeVariant, int cVars)
Have you tried this method?
object[] result;
unsafe
{
pin_ptr<object> pinObj = &obj;
result = Marshal.GetObjectsForNativeVariants(new IntPtr(pinObj), objSize);
}
Haven't tried it myself but seems like it would do the trick.
This is the C# function declaration:
public double[][] CalcMatching( object[][] data1, object[][] data2, long dataLen1, long dataLen2, string matchingType )
This is the VB6 call:
result = matchingCalcObj.CalcMatching(data1, data2, dataLen1, dataLen2, Matching)
where data1
and data2
are arrays of Variant.
I don't think I can do much at the C#, like you guys are saying, once the error I get at the function calling is "Invalid procedure call or argument". Any option at the VB6 side?
Thanks for all the replies.