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

Discussion in 'Microsoft VC .NET' started by BartMan, Jun 6, 2008.

  1. BartMan

    BartMan Guest

    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!
     
    BartMan, Jun 6, 2008
    #1
    1. Advertisements

  2. >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
     
    David Lowndes, Jun 6, 2008
    #2
    1. Advertisements

  3. BartMan

    BartMan Guest

    Re: How to convert an unmanaged unsigned char* buffer into a byte

    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!
     
    BartMan, Jun 9, 2008
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tomas Restrepo \(MVP\)

    Re: unsigned char to unsigned char __gc[]

    Tomas Restrepo \(MVP\), Aug 31, 2003, in forum: Microsoft VC .NET
    Replies:
    2
    Views:
    2,038
    Tomas Restrepo \(MVP\)
    Aug 31, 2003
  2. Sergey Muschin
    Replies:
    1
    Views:
    518
    Sergey Muschin
    Jan 21, 2004
  3. Eki Y. Baskoro

    Re: 'unsigned char __gc[]' to 'unsigned char __gc *'

    Eki Y. Baskoro, Mar 15, 2005, in forum: Microsoft VC .NET
    Replies:
    0
    Views:
    393
    Eki Y. Baskoro
    Mar 15, 2005
  4. joye
    Replies:
    1
    Views:
    1,233
    Eckart Haug
    Jul 21, 2005
  5. joye
    Replies:
    5
    Views:
    475
Loading...

Share This Page