Interop, Late Binding and Array of longs

S

Sam

Hello All,

I have this VB 6 code :

'******************************************************************
' Purpose :
' Initialize an array with available metric for the selected
component
'
' Parameters :
' lArray : array to fill
'
'******************************************************************
Public Sub AvailableMetrics(lArray() As Long)
Dim i As Integer
' uUnitArray exists
ReDim lArray(0 To UBound(uUnitArray))

For i = 0 To UBound(uUnitArray)
lArray(i) = uUnitArray(i).MetricId
Next i

End Sub

I'd want to perform an IDispatch call (late binding) to pass by
reference an array, but i get a Type mismatch exception with the
following C# code :

public static object CallMethodArray(object instance, string
methodName, object[] parameters)
{
try
{
ParameterModifier[] mods = new ParameterModifier[1] {
new ParameterModifier(1) };
mods[0][0] = true;
return instance.GetType().InvokeMember(methodName,
memberAccess | BindingFlags.InvokeMethod, null, instance,
parameters,mods,null,null);
}
catch (TargetInvocationException e)
{
if (e.InnerException != null)
log.Debug("Call Invocation failed :" +
e.InnerException.Message);
throw e;
}
}

Any idea?

thanx

Sami
 
C

chanmm

Do you mean you call AvailableMetrics from C#? I did not see you are
calling AvailableMetrics.

chanmm
 
S

Sam

Yes Sorry, CallMethodArray is just a Helper method.

Here is the whole thing :

long[] tabMetrics=new long[11]; // Or whatever size
InteropUtil.CallMethodArray(targetComObject,
"AvailableMetrics", new object[] { new long[] { 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0 } });

CallMethodArray throw an exception : Exception from HRESULT: 0x80020005
(DISP_E_TYPEMISMATCH) ...

Sam
 
W

Willy Denoyette [MVP]

A long in C# is a 64 bit integer, a long in VB is 32 bit!!

Willy.

| Yes Sorry, CallMethodArray is just a Helper method.
|
| Here is the whole thing :
|
| long[] tabMetrics=new long[11]; // Or whatever size
| InteropUtil.CallMethodArray(targetComObject,
| "AvailableMetrics", new object[] { new long[] { 0, 0, 0, 0, 0, 0, 0, 0,
| 0, 0, 0 } });
|
| CallMethodArray throw an exception : Exception from HRESULT: 0x80020005
| (DISP_E_TYPEMISMATCH) ...
|
| Sam
|
 
S

Sam

Yes you are rigth, but i have also tested Int32 (signed and unsigned)
C# type with no more success (i have the same exception)
How would you pass by reference an array (by ref) between C# and VB6
thru COM ?
thanx in advance
Sam
 
S

Sam

Sam a écrit :
Yes you are rigth, but i have also tested Int32 (signed and unsigned)
C# type with no more success (i have the same exception)
How would you pass by reference an array (by ref) between C# and VB6
thru COM ?
thanx in advance
Sam

Maybe I should post this thread in Interop newsgroup....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top