0

I am trying to call a function in C from C# though c ++

so basically C# -> C++ - >C

In C#, I have byte[] bytes - which reads the information from the file. I am passing the byte array and the size to C++ .

In C++ I get the byte array and the size but I am not able to convert to the specific data types.

void Image::OpenMemFile(array<Byte>^ data, unsigned int size)
{

    Free();
    m_dataStream = data;
    Byte const* streamData = &data[0];   // this is where it throws error 
         // Should I use marshaling here ? What call should that ;be ?
         hImage = ::OpenMemImage(streamData ,&nbsp;size);
    modified = false;
}

// this is the function I&nbsp;need to call 
EXIVSIMPLE_API HIMAGE OpenMemImage(const&nbsp;BYTE *data, unsigned int size)
{
   // code
        imgWrap->image = Exiv2::ImageFactory::open(data, size);

}

the C function it needs to call is

Image::AutoPtr ImageFactory::open(const byte* data, long size)
    {
      /// code
    }

I need to help in converting the byte array to const byte* . I realize I need to use Marshaling. Is there a specific function to marshal arrays in C++ ?

Any help is appreciated.

Thanks

1 Answer 1

1
pin_ptr<unsigned char> pin_buffer = &data[0];
unsigned char* pData = pin_buffer;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.