>where lpData is a pointer to a string sSysEx, which is filled by an API call
>back routine (using that pointer).
I suggest using an unmanaged memory block allocated with one of the
Marshal.Alloc* methods instead of using a pinned string here. Managed
strings are meant to contain Unicode text, nothing else.
>because IntPtr is part of a struct and the VB Len function cannot determine
>its length.
Use Marshal.SizeOf instead of Len.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reinier VDW - 18 Nov 2004 22:21 GMT
Thanks for your help.
I marshaled the struct MIDIHDR and Marshal.SizeOf is fine.
However, how should I marshal the string sSysEx?
Dim mypointer as IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sSysEx)) is
not OK as sSysEx is not a struct.
Do you have an example on the Marshal.Alloc* stuff?
Thanks again for your help.
Reinier
"Mattias Sjögren" wrote:
> >where lpData is a pointer to a string sSysEx, which is filled by an API call
> >back routine (using that pointer).
[quoted text clipped - 9 lines]
>
> Mattias
Mattias Sj?gren - 19 Nov 2004 23:56 GMT
>Dim mypointer as IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(sSysEx)) is
>not OK as sSysEx is not a struct.
>Do you have an example on the Marshal.Alloc* stuff?
You said that the called function would fill the buffer right? Then
just allocate a memory block with a fixed size, like this
Dim mypointer as IntPtr = Marshal.AllocHGlobal(size)
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Reinier VDW - 20 Nov 2004 20:07 GMT
OK, thank you for your help!
Reinier