praetor
2009-04-21 15:55:01 UTC
I haven't found any comprehensive sample code on this topic. Lots of pages
cover C++ VARIANT and SAFEARRAYS, but nothing covering C# interoperability.
I need to consume an existing service in C++ using C#. Previous clients
used VB6 arrays. To paraphrase, I have a method in C++:
int __stdcall DoSomething( VARIANT *pvArray );
I have tried calling this method using the following:
TRIAL #1
[DllImport("binary.dll")]
private static extern DoSomething( ref [] object vArray );
(...)
Object [] variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = vP.ToArray();
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
TRIAL #2
[DllImport("binary.dll")]
private static extern DoSomething( ref object vArray );
(...)
Object variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = vP.ToArray();
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
TRIAL #3
[DllImport("binary.dll")]
private static extern DoSomething( ref object vArray );
(...)
Object variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = new VariantWrapper(vP.ToArray());
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
I have tried a bunch of other stuff; but I have ommitted them for brevity.
Everytime I debug the C++, by variant pointer is ALWAYS null.
Are there any comprehensive samples out there on how to get something like
this done?
Thanks,
James
Beverly, MA
cover C++ VARIANT and SAFEARRAYS, but nothing covering C# interoperability.
I need to consume an existing service in C++ using C#. Previous clients
used VB6 arrays. To paraphrase, I have a method in C++:
int __stdcall DoSomething( VARIANT *pvArray );
I have tried calling this method using the following:
TRIAL #1
[DllImport("binary.dll")]
private static extern DoSomething( ref [] object vArray );
(...)
Object [] variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = vP.ToArray();
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
TRIAL #2
[DllImport("binary.dll")]
private static extern DoSomething( ref object vArray );
(...)
Object variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = vP.ToArray();
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
TRIAL #3
[DllImport("binary.dll")]
private static extern DoSomething( ref object vArray );
(...)
Object variant;
System.Collections.ArrayList vP = new System.Collections.ArrayList();
vP.Add( (ulong)12345 );
variant = new VariantWrapper(vP.ToArray());
CAScc_CompleteWorkVariant(m_hAgent, "101", 0, ref variant, "");
I have tried a bunch of other stuff; but I have ommitted them for brevity.
Everytime I debug the C++, by variant pointer is ALWAYS null.
Are there any comprehensive samples out there on how to get something like
this done?
Thanks,
James
Beverly, MA