How to convert an unmanaged unsigned char* buffer into a byte [] a

B

BartMan

Greetings,

I am working on a project where the interface from the UI application (done
in C#) requires that an image buffer be passed back as a byte[] array as
defined by an interface.

The problem is that the device uses a legacy c style buffer of unsigned
char* to hold its image data. I wrote a C++\Clr wrapper around the legacy c
stuff. Which is working really well with other features of the device.

But now I am trying to figure out how I can get my legacy buffer into a
byte[] buffer that the .Net application is requesting?

For example:
// The .Net C# defined interface
interface IImageRetrieval
{
void GetImage(byte [] buffer);
}

// C++\Clr object
public ref class TestClass : public IImageRetrieval
{
public:
virtual void GetImage(System::Byte [] buffer)
{
unsigned char* pBuffer = contains jpeg image data from a device.

// HOW DO I CONVERT THE UNMANAGED TO MANAGED BYTE [] for C#?
buffer = pBuffer????

}
};

Thanks in advance for any suggestions!
 
D

David Lowndes

But now I am trying to figure out how I can get my legacy buffer into a
byte[] buffer that the .Net application is requesting?

Have a look on MSDN for "How to: Marshal Arrays Using C++ Interop"

Dave
 
B

BartMan

Hello David,

Thank you for the heads up, it lead me to the section:
"How to: Load Unmanaged Resources into a Byte Array" which is what I needed.

Thanks again!
 

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