[Mono-list] copying pointer data without unsafe code ?

Glenn Pierce glennpierce@connectfree.co.uk
Thu, 30 Sep 2004 18:37:46 +0100


Hi

I am trying to wrap a c image library and having trouble getting the
data using P/Invoke.

The client C code would be:


void* buf;
buf = malloc (bufsize);
retval = GetImageData (buf, bufsize);


What I need is to get the image data into a managed array. 


Currently I am using unsafe code to get the data into a void pointer,
with:

[DllImport(Library)]
private unsafe extern static uint IcsGetData (void* dest, uint n);

I tried experimenting with [Out] System.Array as I don't know the necessary image type
until runtime and so I don't know the type of array. However, I had with no luck with this method.


After I have the pointer to the image data I then copy the data into a managed array
by using code to allocate unmanaged memory as seen http://www.asprelated.com/csharp/sharp-18_8.aspx.



Is there an easier way I can get the image data into a managed array without using unsafe code ?


Thanks for any help.


Glenn