PDA

View Full Version : Using ImageBuffer.GetImageData() pointer in native c++



Virdung
March 13, 2009, 12:30:38
I have a question on ImageBuffer.GetImageData().

We have a c++ dll that is supposed to take a pointer (or some object containing) to the raw image data of an imagebuffer. Is there a way of doing this?

Now we pass the byte* from GetImageData to a c++ Function taking a char*.
When trying to access this memory we get MemoryAccessviolationexception.
(Tried with a simple memcpy with the same result)

We assume that the memory block is of size height*width*bytesperpixel.

One possible solution would be to use the c++ class library instead but the rest of the application (excluding the c++dll) will be written in c# so if that could be avoided it would be good.

Regards
Martin

Stefan Geissler
March 16, 2009, 11:28:20
Martin,

I suggest to use a memcpy and copy the the complete memory into an own memory block for your C++ DLL. This may avoids the problem. You should perform the memcpy in your C# code, not in the C++ DLL

Virdung
March 20, 2009, 16:36:46
Thanks,

I guess I had some other memory problems as well.

Now I use the byte* and forward it down to the c++ layer and it seem to work.

/Martin