[Mono-devel-list] IntPtr and accessing structures

Jonathan Turner joturner at vt.edu
Thu Aug 12 00:08:47 EDT 2004


Hopefully this is the correct list.  I couldn't find a "mono-users" or
"mono-beginner-developers" list.

My question's pretty straight forward.

I'm trying to connect to SDL using the Tao.Sdl.  I use:

IntPtr mySurface = Sdl.SDL_SetVideoMode(640, 480, 16,
Sdl.SDL_SWSURFACE);

Which gives me a window.  That's great, exactly what I wanted.

Now I want to access mySurface, but it's an IntPtr, so I can't access
any members that are SDL_Surface type members.  I'm a C/C++ guy, so I
think let's cast it.

I try something like:

unsafe {
	Sdl.SDL_Surface *mySurfaceReal = (Sdl.SDL_Surface *)mySurface.ToPointer
();
	Console.WriteLine("Surface bytes per: {0}", mySurfaceReal->pitch);
	Console.WriteLine("Width: {0}", mySurfaceReal->w);
	Console.WriteLine("Height: {0}", mySurfaceReal->h);
	Console.WriteLine("My address for pixels: {0}", mySurfaceReal->pixels);
}

Which doesn't work.

Any ideas?

I'm trying to get to the pixels member, which is a pointer to the screen
data.  Once I learn how to manipulate that I'm off and running, it's
just these bits I can't seem to wrap my head around.

Jonathan




More information about the Mono-devel-list mailing list