[Mono-dev] Marshalling (Segmentation fault)

russell.kay at realtimeworlds.com russell.kay at realtimeworlds.com
Thu Oct 11 07:19:39 EDT 2007


The C# version of this Structure would be best expressed as

[StructLayout(LayoutKind.Explicit)]
unsafe struct FrameGrab
{
	[FieldOffset(0)]
	public int bufferlength;
	[FieldOffset(4)]
	Public fixed IntPtr buffer[1000]
}

One question are you definitely wanting an array of 1000 pointers.... if
it is really 1000 bytes you are wanting then it would look like

[StructLayout(LayoutKind.Explicit)]
unsafe struct FrameGrab
{
	[FieldOffset(0)]
	public int bufferlength;
	[FieldOffset(4)]
	Public fixed byte buffer[1000]
}

Accessing this array on the C# side would then be through a bit of
unsafe code

Public void DoSomething( IntPtr _pValFromCPP )
{
unsafe {
	fixed( FrameGrab* pFG = (FrameGrab*)_pValFromCPP.ToPointer()) {
		IntPtr p = pFG->buffer[0];
	// or
		Byte b = pFG->buffer[0];
	}
}
}

Russell

-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Abir
Bhattacharya
Sent: 11 October 2007 12:09
To: 'Robert Jordan'; mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] Marshalling (Segmentation fault)

The 'C' prototype :



#ifndef PICTURE_H
#define PICTURE_H

#include "def.h"


struct fgrab {
	int bufferlength;
	unsigned char *buffer[1000];
} typedef fgrab_struct;


fgrab_struct fbuffergrab();
void fbufferflush(fgrab_struct fgbuffer);

#endif

-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com] On Behalf Of Robert
Jordan
Sent: Thursday, October 11, 2007 4:32 PM
To: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] Marshalling (Segmentation fault)

Abir Bhattacharya wrote:
> 
> [DllImport ("lib.so")]
> 
> Private static extern ImgStruct gbuffergrab(); // gbuffergrab is the
'C'
> method which returns type struct

Please post the C prototype as well.

Robert

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




-- Visit us at http://www.2pirad.com/ --
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

____________________________________________________________________
This email has been scanned by the MessageLabs Email Security System

DISCLAIMER
This message and any attachments contain privileged and confidential information intended for the use of the addressee named above. If you are not the intended recipient of this message, you are hereby notified that any use, dissemination, distribution or reproduction of this message is prohibited. Please note that we cannot guarantee that this message or any attachment is virus free or that it has not been intercepted and amended. The views of the author may not necessarily reflect those of Real Time Worlds Ltd.
____________________________________________________________________
This email has been scanned by the MessageLabs Email Security System



More information about the Mono-devel-list mailing list