Passing managed array to unmanaged function C++

Posted on 2010-04-04
Medium Priority
Last Modified: 2012-05-09

how can i pass a managed array of bytes
array<byte> to an unmanaged function

void fillArray(unsigned char ** yrArray);

the function will fill the array.

Question by:jaxrpc
LVL 86

Expert Comment

ID: 29697036
Take a look at

http://msdn.microsoft.com/en-us/library/9b1fy41s(VS.80).aspx ("How to: Marshal Arrays Using C++ Interop")


http://msdn.microsoft.com/en-us/library/bd99e6zt.aspx ("How to: Marshal Arrays Using PInvoke")

depending on which method you are using. Both articles come with full sample code.
LVL 39

Accepted Solution

itsmeandnobodyelse earned 2000 total points
ID: 29901746
>>>> void fillArray(unsigned char ** yrArray);

That function prototype is not suitable for being called from managed C++. It has a pointer to pointer as argument what means it is designed to *return* a pointer to char array rather than to only fill an array passed.

The fillArray should have prototype

  void fillArray(unsigned char yrArray[], int sizArr);

where sizArr is the size of the byte array passed.


Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

599 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question