It's impossible to know without you providing us the function prototype
getting called.
It's *probably* a ptr to a null-terminated char array.
An API that returns data without providing a size in some way is not
usable, so I'm sure it's there somewhere.
Post more info and we can help!
Tom
> I am using Interop with a C++ function which returns a pointer to an
> array of bytes. I'm using an IntPtr and Marshal.Copy to populate a
[quoted text clipped - 3 lines]
> way of accomplishing this? Should I be using IntPtr at all in this
> scenario?
fredrik.claesson@gmail.com - 19 Sep 2006 21:11 GMT
Hello,
This post has an interesting connection to a problem I am dealing with
currently.
I send an unmanaged array (unsigned chars) från unmanaged C++ to C#
using P/Invoke and a callback/delegate.
I use Marshal.Copy to copy the data to a managed array. For performance
reasons I would perfer not to copy the data (large images) at all.
However as I have control of the allocation of the unmanaged array and
would like to create a managed "wrapper" array (which is considered to
be pinned by the GC) which points to the unmanaged data.
I have not been able to do this and and am therefore wondering if there
are reasons for not doing this at all? As the binary layout of the
managed array is just like a normal unmanaged array it would not seem
impossible to do this.
A solution which does not require me to copy the data is to allocated a
managed array, pin the data (using a GCHandle) and pass it to the
unmanaged code. Is this the only "no-copy" transfer of arrays from
unmanaged to managed code possible?
/Fredrik
> It's impossible to know without you providing us the function prototype
> getting called.
[quoted text clipped - 15 lines]
> > way of accomplishing this? Should I be using IntPtr at all in this
> > scenario?
fredrik.claesson@gmail.com - 19 Sep 2006 21:45 GMT
Hej!
Seem like I find the answer when I review older post. In the post
"Is Marshal.Copy() really necessary to pass an array to/from
managed/unmanaged code?" Mattias Sjögren answers a similar question.
So it appear I could try using
the unsafe keyword to access to data directly.
/Fredrik
> Hello,
>
[quoted text clipped - 20 lines]
>
> /Fredrik