PC Review


Reply
Thread Tools Rate Thread

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

 
 
BartMan
Guest
Posts: n/a
 
      6th Jun 2008
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!






 
Reply With Quote
 
 
 
 
David Lowndes
Guest
Posts: n/a
 
      6th Jun 2008
>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
 
Reply With Quote
 
 
 
 
BartMan
Guest
Posts: n/a
 
      9th Jun 2008
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot convert from unsigned short to unsigned short????? Bo Berglund Microsoft VC .NET 2 9th Apr 2007 03:26 PM
Best way to use unmanaged buffer as a Byte []? preferably w/o copying from native to managed memory lallous Microsoft VC .NET 1 27th Mar 2007 04:02 PM
Re: 'unsigned char __gc[]' to 'unsigned char __gc *' Eki Y. Baskoro Microsoft VC .NET 0 15th Mar 2005 09:57 AM
how to convert native strusture to unsigned char buffer __gc[] Sergey Muschin Microsoft VC .NET 1 21st Jan 2004 07:36 PM
Re: unsigned char to unsigned char __gc[] Tomas Restrepo \(MVP\) Microsoft VC .NET 2 31st Aug 2003 08:52 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:09 PM.