473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Interop, Late Binding and Array of longs

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

May 29 '06 #1
5 1994
Do you mean you call AvailableMetrics from C#? I did not see you are
calling AvailableMetrics.

chanmm


"Sam" <sa********@gmail.com> wrote in message
news:11**********************@38g2000cwa.googlegro ups.com...
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

May 29 '06 #2
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

May 29 '06 #3
A long in C# is a 64 bit integer, a long in VB is 32 bit!!

Willy.

"Sam" <sa********@gmail.com> wrote in message
news:11**********************@j73g2000cwa.googlegr oups.com...
| 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
|
May 29 '06 #4
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

May 29 '06 #5
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....

May 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JL_327 | last post by:
No one on any of the other boards seem to know In VB.Net this late binding works fine Dim Version As Integer Dim Revision As Integer Dim Wnum As Integer Dim o As System.Array =...
0
by: JL_327 | last post by:
No one on any of the other boards seem to know In VB.Net this late binding works fine Dim Version As Integer Dim Revision As Integer Dim Wnum As Integer Dim o As System.Array =...
3
by: Thomas Müller-Lynch | last post by:
How can I avoid late binding with the directive strict = tru My ASP .net-file looks like this <%@DEBUG=true TRACE=true Strict=false EXPLICIT=true% .. dim footerValues as Arra footerValues =...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
5
by: John | last post by:
Hi I need to call methods from office apps from my vb.net app. Some of my clients are still on office 2000 so to maintain compatibility I can not use office 2003 PIA. Can I avoid the whole PIA...
9
by: Miro | last post by:
VB 2003 and Im still new to vb, so i hope i can explain this as best I can. I have a variable defined as such: ( simple example ) Dim AVariableOfSorts(,) As Object = _ { _ {"Last", "String",...
1
by: Adotek | last post by:
Hi All, I've just converted a solution from .Net v1.1 to v2.0, by allowing Visual Studio 2005 to do the conversion. Since doing so, I am getting a compilation error as follows: "Option...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
4
by: =?Utf-8?B?cGJsYWNrYnVybg==?= | last post by:
Summary Getting the error message Run time error 424 Object Required when attempting to assign a value to a C# COM visible property of type object. I have created a COM visible class as below ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.