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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?QmFydE1hbg==?=

    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!






  • David Lowndes

    #2
    Re: How to convert an unmanaged unsigned char* buffer into a byte [] a

    >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

    Comment

    • =?Utf-8?B?QmFydE1hbg==?=

      #3
      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!

      Comment

      Working...