[Gtk-sharp-list] Marshaling question
Paolo Molaro
lupus@ximian.com
Tue, 4 Mar 2003 19:30:26 +0100
On 02/27/03 Charles Iliya Krempeaux wrote:
> I am creating C# a method with the following signature:
>
> public override int Read(byte[] buffer, int offset, int count);
>
> Here, "buffer" (will eventually) contain the stuff that got read.
> "offset" tells you where to start storing stuff in "buffer".
> ("offset" used a zero based index.) And "count" is the maximun
> number of bytes to read from the current stream. Also, it returns
> the total number of bytes read from the stream.
>
> Now, I'm using this to wrap the GnomeVFS procedure:
>
> GnomeVFSResult gnome_vfs_read(GnomeVFSHandle *handle ,
> gpointer buffer ,
> GnomeVFSFileSize bytes ,
> GnomeVFSFileSize *bytes_read );
>
> The problem I am having is with "buffer" in "gnome_vfs_read". I
> need to get a the get at the pointer for "Read"'s buffer. In
> pseudo code, this is basically what I want to do...
>
> public override int Read(byte[] buffer, int offset, int count)
> {
>
> byte * bufferptr = (byte * ) buffer;
>
> bufferptr = bufferptr + offset;
>
> // ...
>
> Although, I am not sure how to do this. Anyone here have any
> ideas?
>
> (I.e., anyone know how to get a pointer to "buffer"'s memory
> buffer?)
Use:
fixed (byte *ss = &buffer [offset]) {
gnome_vfs_read (handle, ss, ...);
}
Give or take the proper declaration for gnome_vfs_read.
lupus
--
-----------------------------------------------------------------
lupus@debian.org debian/rules
lupus@ximian.com Monkeys do it better