473,327 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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!


Jun 27 '08 #1
2 3559
>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
Jun 27 '08 #2
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!

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Don | last post by:
I have a third party C++ DLL that I am trying to use from C#. The specific function I am trying to use is declared in C++ as follows: ladybugConvertToMultipleBGRU32( LadybugContext ...
5
by: Saya | last post by:
Hi, Please help with the following: How to implement a C++ code like this: MediaFunction( char* filename, void* info, int* size, void** buffer, int first, int* last);
5
by: kevinniu | last post by:
Hi everyone, In c#, what is the fastest way(include unsafe) to convert a array of bytes(which really contains the bytes of a double array) to a arry of double. thanks
3
by: Lee Crabtree | last post by:
I have a managed DLL that I've used to expose a C++ class. One of the functions in this class reads a line out of a file into a buffer of type "unsigned char*". Since all the data is just...
4
by: msosno01 | last post by:
I have Java client that connects to C++ server. The client sends integer in binary using DataOutputStream write function. I am reading these data into buffer. I have to convert this buffer back...
8
by: Polaris431 | last post by:
I have a buffer that holds characters. Four characters in a row represent an unsigned 32 bit value. I want to convert these characters to a 32 bit value. For example: char buffer; buffer =...
7
by: Tremendo | last post by:
Hi, I need to consume an unmanaged DLL from managed C#. The DLL is "ae766.dll". I have problems with one function in it. Who developed the DLL, provided the following information, regarding that...
2
by: eusebiu | last post by:
Hello... I am making a Sytem.IntPtr with Marshal.AllocHGlobal(int) (Allocates memory from the unmanaged memory of the process using GlobalAlloc - MSDN Definition for Marshal.AllocHGlobal) and after...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.