Problem calling a .COM component in :NET with C#

A

Alfonso

Hello,


I am implementing a hanwritting recognition benchmark, and when
calling from
my C# code the API of a HWr engine I have the following

Code:

int[] strokes = {myInt1, myInt2, myInt3, myInt4};
ink.AddStroke(strokes);

problem:

Argument '1': cannot convert from 'int[]' to 'ref System.Array'

Description of API:

4.2.2.1 AddStroke, AddStrokeXY
Index = object .AddStroke(Ink ) Index = object .AddStrokeXY(InkX, InkY
)
Description
Adds a stroke to the object.
Returns assigned zero-based index of the added stroke in the stroke
array.
o object is an object expression that evaluates to a riteFormInk
object.
o Ink is an array of Longs (in Visual Basic) or Integers (in VB.NET),
representing
strokes (X-value in the lower word and Y-value in the upper word).
o InkX is an array of Integers (in Visual Basic) or Shorts (in
VB.NET), represented X-values
of points.
o InkY is an array of Integers (in Visual Basic) or Shorts (in
VB.NET), represented Y-values
of points.
o Index is a variable of the type Long (in Visual Basic) or Integer
(in VB.NET) or
Variant.
Comment
Those methods cannot be used in scripting languages that doesn't
support typed variables
(like VBScript and JScript).



I have another code implementet VB .NET which calls the same function
with an array of Ints and works well.

Any hint?

thanks


Alfonso
 
M

Murat KARATUTLU

The problem might not be Array type but the argument type.
as you see the API function accepts a reference (byref in VB, ref in C#) to
the array of integers, the the array itself.
So you may declare a variable to reference the array and send it to the
function as an [in] arg.

e.g.

to call a function like:
void SomeFunction(ref int x, int y) {
//implementation goes here
}

you should:
int _x = 10;
int _y = 20;

SomeFunction(ref _x, _y);

but you can NOT
SomeFunction(10, 20);

PS: Also casting may be required for the array type
 

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