Cannot convert to System.IntPtr

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daisy

    #1

    Cannot convert to System.IntPtr

    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.Hard ware, _form,
    CreateFlags.Sof twareVertexProc essing, _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(IntP tr form)
    {
    _form = form;
    _device = new Device(0, DeviceType.Hard ware, _form,
    CreateFlags.Sof twareVertexProc essing, _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 The Cow
    Now playing: Darude Vs Robert Miles - Sandstorm Children


  • codymanix

    #2
    Re: Cannot convert to System.IntPtr

    maybe a simple cast will help?

    --
    cody

    [Freeware, Games and Humor]
    www.deutronium.de.vu || www.deutronium.tk


    Comment

    • Daisy

      #3
      Re: Cannot convert to System.IntPtr

      "codymanix" <dont.spam.me.d eutronium@gmx.d e> wrote in message
      news:%23Vjrczrt DHA.536@tk2msft ngp13.phx.gbl.. .[color=blue]
      > maybe a simple cast will help?[/color]

      Nope, just gives the error on the line with the cast:

      Cannot convert Game3d.Game to System.IntPtr :(
      --
      Daisy The Cow
      Now playing: Nothing


      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: Cannot convert to System.IntPtr

        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

        "Daisy" <daisy@nospam.o ops> wrote in message
        news:f64yb.1685 $PR.13920@newsf ep4-glfd.server.ntl i.net...[color=blue]
        > Having a weird problem... Just moving some code into new classes &[/color]
        methods.[color=blue]
        >
        > Originally, I created a new instance of "Game" (my form), and it created a
        > new DX Device using:
        >
        >
        > _device = new Device(0, DeviceType.Hard ware, _form,
        > CreateFlags.Sof twareVertexProc essing, _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(IntP tr form)
        > {
        > _form = form;
        > _device = new Device(0, DeviceType.Hard ware, _form,
        > CreateFlags.Sof twareVertexProc essing, _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[/color]
        own[color=blue]
        > classes? :-\
        > --
        > Daisy The Cow
        > Now playing: Darude Vs Robert Miles - Sandstorm Children
        >
        >[/color]


        Comment

        • Daisy

          #5
          Re: Cannot convert to System.IntPtr

          "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
          news:OfODKPstDH A.1744@TK2MSFTN GP12.phx.gbl...[color=blue]
          > An IntPtr is not a Form, a Form is not an IntPtr, how do you expect to[/color]
          pass[color=blue]
          > one to the other???
          >
          > Are you thinking you want to pass the handle to the Form to your[/color]
          GameEngine?[color=blue]
          >
          > 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[/color]

          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 :-)
          --
          Daisy The Cow
          Now playing: Nothing


          Comment

          Working...