Passing an array of bytes from C++ to C#
Hi All,
I am trying to write a C# program to call a routine in managed C++.
In the routine, the C# program passes a delegate to the managed C++.
The delegate looks like this in c++:
public __delegate void FoundPidDelegate (
unsigned char pData __gc[],
);
My C# routine looks like this:
static private void MyFoundPidFunction (byte []pData)
The C++ program should call the delegate and pass it an array of bytes (or at least the address of an array of bytes).
In C++ I am allocating the memory like this:
unsigned char arrManaged __gc [] = new unsigned char __gc[iDataLen];
Then I call the C# delegate routine like this:
m_pFoundFunc(arrManaged);
When I arrive back in my C# program, the pData array only has ONE
element (a correct one) and if I try to look at pData[1], I get an error.
What am I doing wrong?
Thanks!
Josh

bilnaadRank #2,169 · 655 reputationPosted Nov 18, 2004, 8:16 AM EST
jmales5 reputationPosted Nov 21, 2004, 3:52 AM EST
bilnaadRank #2,169 · 655 reputationPosted Nov 21, 2004, 8:26 AM EST
jmales5 reputationPosted Nov 22, 2004, 1:55 AM EST
John ArcadellaRank #1,064 · 1.8K reputationPosted Dec 17, 2004, 8:09 AM EST