[Mono-list] accessing struct instance from managed code

Nigel Benns nigel_benns@rogers.com
Mon, 28 Feb 2005 08:16:40 -0500 (EST)


Sorry for the crappy explanation, it was friday and I was tired ;)

yeah... its basically a GTK+ type of idea.
The structure is for ewl_window
and ewl windows' struct has an EVAS object in it that i can access as

window->evas;

So basically I should wrap this a getter function from C# and make a C
function that returns the evas addr like this then:

int *ewl_window_evas_get(Ewl_Window *win) {

   return win->evas;

};

This is kindof what I wanted to avoid if possible, but if its going to
cause a whole bunch of Managed -> Unmanaged speghetti any other way, then
I would rather do it this way. :)

> On Fri, 2005-02-25 at 14:02 -0500, Nigel Benns wrote:
>> ok... this is the lowdown :)
>>
>> in C:
>>
>> struct try {
>>
>>    int *blah;
>>
>> }
>
> In C#:
>
> 	struct try {
> 		public System.IntPtr blah;
> 	}
>
>> int main() {
>>
>>    object *meh;
>>    int *thing;
>>
>>    meh = try_new();
>>
>>    thing = meh->blah; //this is what I want to do from C#
>>
>> }
>
> In C#:
>
> 	class Test {
> 		[DllImport ()]
> 		private static extern IntPtr try_new ();
>
> 		public static void Main ()
> 		{
> 			System.IntPtr meh = try_new ();
> 			try t = (try)
> 			  System.Runtime.InteropServices.Marshal
> 			  .PtrToStructure (meh, typeof(try));
>
> 			System.IntPtr thing = t.blah;
> 			int thing_value =
> 			  System.Runtime.InteropServices.Marshal
> 			  .ReadInt32 (thing);
> 		}
> 	}
>
> Note: I haven't actually compiled this, but it should work.
>
> Also, I'm not sure what an `object*' is supposed to be in your C code.
> If you're trying to use GTK+-style OO programming, things will be very
> different, and a glue library should instead be used.
>
>  - Jon
>
>
>