out keyword (function prototype)

  • Thread starter Thread starter [GHO}
  • Start date Start date
G

[GHO}

I trying to send an array to my C# dll function which the
prototype as "C# COM (Dll)":

public int PrintIO(out System.Int64 [] FreeIO ,out int len)

But when trying to call this function (CPP file)

__int64 *heelp;
int len=0;
if (cpi->PrintIO(&heelp,&len) == 0)


i get the following error:

"
COMClient.cpp(60): error
C2664: 'IManagedInterface::PrintIO' : cannot convert
parameter 1 from '__int64 ** ' to 'SAFEARRAY ** '
"
 
i get the following error:

"
COMClient.cpp(60): error
C2664: 'IManagedInterface::PrintIO' : cannot convert
parameter 1 from '__int64 ** ' to 'SAFEARRAY ** '
"

This is more of a C++ question, but basicly you have to create a
SAFEARRAY and pass in that instead.



Mattias
 
Well, I'm a little new to the C# way of doing things
myself, as you'll see from some of my posts in this forum,
so I'm by no means the authority on the subject but...

It seems to me that your C# fxn wants an array of
pointers, and you're making it an OUT argument, presumably
becasue it will modify the contents of the original array
(otherwise you woldn't pass ti as an out, which is, as I
understand it, effectively passing it by reference instead
of by value). However, you are only passing in the
address of a pinter to an __int64, not a pointer to an
array. Me thinks you might want to change your variable
declaration in the C++ file to

__int64* heelp[20]; // or however many you need.

If you don't know how many you need, then you'll have to
create a (**) (piotner to a pointer... Man I love C++ :-
) )... and then initialize it with something...

__int64 **help; // Pointer to a pointer of __int64
*heelp = new __int64[25];
....
delete *heelp[];

But that might put you right back in the same boat. There
is another fxn in C++ I used to use when donig stuff with
ADO and dynamic arrays, a fxn called "CreateSaffeArray()",
and you might want to take a look at that as well.

Again, I'm not the authoority on C#, nor anything else...
Hehehe.. But I hope that helps you out. If not, let me
know and we can take another stab at it. :)

JIM
 
"create a SAFEARRAY and pass in that instead."
How to do that?

Use the SafeArrayCreateEx API or some wrapper class. I'm sure you can
get more help in this in the C++ newsgroup.



Mattias
 
Look up SafeArray in the help.

//should work
public int PrintIO(([MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VT_I8)]System.Int64 [] FreeIO ,out int len);
 
Back
Top