Thread: Static class?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607

    DirectInput problems

    I'm currently working on mouse support for my tile engine and I've run into problems. The DirectInput object is one interface - created one time. The Mouse interface is as well but I'm deriving it from DirectInput. Problem is that when I create the mouse, keyboard, etc - I do not want to create another instance of DirectInput.

    If I declare DXInput as static, will this work?
    It seems that MSVC does not like that, but I thought this was possible with classes?


    Here is my setup:

    DXInput.h
    Code:
    #ifndef _DXINPUT_
    #define _DXINPUT_
    
    #define DIRECTINPUT_VERSION 0x0700
    #include "dinput.h"
    
    class DXInput
    {
      protected:
        LPDIRECTINPUT lpdi;
      public:
        DXInput(HINSTANCE instance);
        ~DXInput(void) {if (lpdi) lpdi->Release();};
    };
    
    #endif
    DXInput.cpp
    Code:
    #include "DXInput.h"
    
    DXInput::DXInput(HINSTANCE instance)
    {
    	
      if (FAILED(DirectInputCreate(instance,DIRECTINPUT_VERSION,&lpdi,NULL)))
      {
        //error
      }
    }
    DXMouse.h
    Code:
    #ifndef _DXMOUSE_
    #define _DXMOUSE_
    
    #include "DXInput.h"
    
    #define RMB 0
    #define LMB 1
    #define MMB 2
    
    class DXMouse:public DXInput
    {
      LPDIRECTINPUTDEVICE lpdiMouse;
      DIMOUSESTATE MouseState;
      public:
        DXMouse(void) {};
        ~DXMouse(void) 
        {
            if (lpdiMouse) lpdiMouse->Unacquire();
            if (lpdiMouse) lpdiMouse->Release();
        }
        void Query(void) {if (FAILED(lpdiMouse->GetDeviceState(sizeof(DIMOUSESTATE),(LPVOID)MouseState))) };
        int CheckButton(int ButtonToCheck);
        void Show(void);
        void Hide(void);
        DIMOUSESTATE GetMouseState(void) {return MouseState;};
    };
    #endif
    DXMouse.cpp
    Code:
    #include "DXInput.h"
    #include "DXMouse.h"
    
    DXMouse::DXMouse(void)
    {
        if (FAILED(lpdi->CreateDevice(GUID_SysMouse,&lpdiMouse,NULL))
       {
         //error
       }
       if (FAILED(lpdiMouse->SetCooperativeLevel(MainWindow,DISCL_BACKGROUND | DISCL_NONEXCLUSIVE)))
      {
        //error
      }
      if (FAILED(lpdiMouse->SetDataFormat(&c_dfDIMOUSE)))
      {
        //error
      }
      if (FAILED(lpdiMouse->Acquire()))
      {
        //error
      }
    }
    
    int DXMouse::CheckButton(int ButtonToCheck)
    {
      Query();
      if (MouseState.rgbButtons[ButtonToCheck] & 0x80)
      {
         return TRUE;
      } else return FALSE;
    }
    Any help would be appreciated. I really want the mouse to be accessible by everyone in the engine. Having to go through a bunch of inheritance crapola when the mouse is a pretty global object seems kinda dumb.

    Right now the compiler is yelling at me about a default constructor for DXInput when I attempt to create the mouse - I understand why it's doing this, but I'm not sure about the best route to go in getting around it.

    And hey, look, all that and no assembly at all.
    Last edited by VirtualAce; 12-21-2003 at 02:44 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. Static member of a class
    By Gravedigga in forum C++ Programming
    Replies: 2
    Last Post: 08-15-2005, 03:54 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. Replies: 3
    Last Post: 10-10-2002, 07:34 AM