Sign in to follow this  

&c_dfDIMouse is UNRESOLVED? (DirectInput C++)

This topic is 2249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason, the data format for a mouse is considered unresolved (linker error 2020)... I've done research, and this seems like my own problem. I couldn't find any info O_o. Any help? Most of my source here is taken (yay plagarism) from the article "Developing a GUI Using C++ and Directx", which the forum faq pointed me too. I just realized it's 6 years old... o_o
#include <dinput.h>
#include <dinputd.h>
#include <dxerr9.h>
#include <d3d9types.h>
#include <windows.h>
#include <atltypes.h>
LPDIRECTINPUT di = NULL;

#define NUMMOUSEBUTTONS 3 // three button mouse  

HWND _hWnd;

typedef struct _Mouse{ 
	LPDIRECTINPUTDEVICE m_mousedev; 
	char m_button[NUMMOUSEBUTTONS]; // state of buttons 
	CPoint m_absposition; // actual screen position 
	CPoint m_relposition; // relative position

	_Mouse(); // boring 
	~_Mouse(); // boring 
	void Init(LPDIRECTINPUT di, HWND hWnd);
	void Refresh(void);
	int GetButton(int index){ 
		if (index < 0 || index > NUMMOUSEBUTTONS) return(0); 
		return(m_button[index]); 
	} 
	void clear(void); // sets all vars to zero 

	// makes sure p is a valid on-screen point 
	void ConstrainPosToScreenSize(CPoint &p); 
	CPoint GetAbsPosition(void) { return(m_absposition); } 
	CPoint GetRelPosition(void) { return(m_relposition); } 
} Mouse;

void _Mouse::clear(){
	int i=0;
	for(i=0;i<NUMMOUSEBUTTONS;i++)
		m_button[i]=NULL; 
	m_absposition.SetPoint(0,0);
	m_relposition.SetPoint(0,0);
}

void _Mouse::Init(LPDIRECTINPUT di, HWND hWnd) 
{
	HRESULT ErrorResult;
	// Obtain an interface to the system mouse device. 
    ErrorResult=di->CreateDevice(GUID_SysMouse, &m_mousedev, NULL); 

	if(FAILED(ErrorResult))
	{
		MessageBox(hWnd, "Creating Mouse Input Device", "ERROR", MB_OK);
		MessageBox(hWnd, DXGetErrorDescription9(ErrorResult),
				DXGetErrorString9(ErrorResult), MB_OK);
	}

	//  Set the data format to "mouse format". 
	ErrorResult=m_mousedev->SetDataFormat(&c_dfDIMouse); //<<----- Here is the problem!
	if(FAILED(ErrorResult))
	{
		MessageBox(hWnd, "Setting Mouse Data Format", "ERROR", MB_OK);
		MessageBox(hWnd, DXGetErrorDescription9(ErrorResult),
				DXGetErrorString9(ErrorResult), MB_OK);
	}
	
	// Set the cooperativity level 
	m_mousedev->SetCooperativeLevel(hWnd, 
		DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); 
}
void _Mouse::Refresh(void){ 
	char done = 0; 
	int q; 
	HRESULT hr; 
	CPoint p; 
	DIMOUSESTATE dims; 

	// clear our struct – eventually, directinput will fill this in 
	memset(&dims, 0, sizeof(DIMOUSESTATE)); 
	if (!m_mousedev) return; // we don’t have a pointer! Bail! 

	while (!done){ 
		// query DirectInput for newest mouse data 
		hr = m_mousedev->GetDeviceState(sizeof(DIMOUSESTATE), &dims); 
		if (FAILED(hr)){ 
			if (hr == DIERR_INPUTLOST || hr == DIERR_NOTACQUIRED) { 
				// device lost... reacquire 
				hr = m_mousedev->Acquire(); 
				if (FAILED(hr)){ 
					// error handling goes here 
					clear(); 
					done=1; 
				} 
			} 
			else { 
				// it’s some other error – handle it 
				clear(); 
				done = 1; 
			} 
		} 
		else /* read mouse successfully! */ { 
		done = 1; 
		} 
	} // end while loop – we’ve read DI correctly 

	// squirrel away newest rel position data 
	m_relposition.x = dims.lX; 
	m_relposition.y = dims.lY; 
	//m_relposition.z = dims.lZ; 
	// now calc abs position from new relative data 
	//m_absposition.z += dims.lZ; 
	m_absposition.x += dims.lX; 
	m_absposition.y += dims.lY; 

	// keep the mouse pointer on-screen... 
	ConstrainPosToScreenSize(m_absposition); 
	// get button data 
	for (q=0; q < NUMMOUSEBUTTONS; q++) { 
		m_button[q] = (dims.rgbButtons[q] & 0x80); 
	} 
}


Share this post


Link to post
Share on other sites
[quote name='Deus Ex Otium' timestamp='1126201412' post='3249351']
It is included. Sorry to be rude; I don't know what else to say...

[/quote]

Hi Deux Ex, did you ever figure out your problem? I'm having the same issue, dxguid.lib is included in the linker, however, I am still getting the Linker error.

Thanks!


Share this post


Link to post
Share on other sites
DIRECTINPUT_VERSION needs to be defined as 0x0700 or higher before you include dinput.h for this format to work. If you have an out of date dinput.h (or an out of date SDK) this obviously won't work.

Share this post


Link to post
Share on other sites

This topic is 2249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this