Cannot convert to System.IntPtr

  • Thread starter Thread starter Daisy
  • Start date Start date
D

Daisy

Having a weird problem... Just moving some code into new classes & methods.

Originally, I created a new instance of "Game" (my form), and it created a
new DX Device using:


_device = new Device(0, DeviceType.Hardware, _form,
CreateFlags.SoftwareVertexProcessing, _presParams);


This works correctly.

I've changed that line to now be:


_engine = new GameEngine(this);


and the constructo for GameEngine looks like this:


IntPtr _form;
public GameEngine(IntPtr form)
{
_form = form;
_device = new Device(0, DeviceType.Hardware, _form,
CreateFlags.SoftwareVertexProcessing, _presParams);
}

And now I get an error about converting Game to System.IntPtr (Game, being
my form).

Have I got to do something special to pass "this" from my forms into my own
classes? :-\
 
Daisy,
An IntPtr is not a Form, a Form is not an IntPtr, how do you expect to pass
one to the other???

Are you thinking you want to pass the handle to the Form to your GameEngine?

You would need to pass Form.Handle (inherited from Control) in that case,
however I would pass Form as Form, then in the constructor save off
Form.Handle.

Hope this helps
Jay
 
Jay B. Harlow said:
An IntPtr is not a Form, a Form is not an IntPtr, how do you expect to pass
one to the other???

Are you thinking you want to pass the handle to the Form to your GameEngine?

You would need to pass Form.Handle (inherited from Control) in that case,
however I would pass Form as Form, then in the constructor save off
Form.Handle.

Hope this helps
Jay

Sorted it now :)
The method was overloaded, and excepts a Form or an IntPtr, and the debugger
had chosen that the incorrect parameter I originally had was closer to an
IntPtr than a Form :-)
 
Back
Top