Archived

This topic is now archived and is closed to further replies.

omegasyphon

mouse input exception handling error

Recommended Posts

alright i have a problem with my windows handleing code and not sure why. when i debug it it goes to the follow line
    
     	lpdi->CreateDevice(GUID_SysMouse,&lpdimouse,NULL);
  

here are the functions i use for init main shutdown for the mouse input. and the game main where it calls the functions.
      

LPDIRECTINPUTDEVICE lpdimouse	= NULL;
LPDIRECTINPUT		lpdi		= NULL;
DIMOUSESTATE		dimouse;
bool				clickhandle;


HWND main_window_handle = NULL; // save the window handle

HINSTANCE main_instance      = NULL; // globally track hinstance




int initcontrols()
{
DirectInputCreate(main_instance,DIRECTINPUT_VERSION,&lpdi,NULL);
	lpdi->CreateDevice(GUID_SysMouse,&lpdimouse,NULL);
	lpdimouse->SetCooperativeLevel(main_window_handle,DISCL_BACKGROUND | DISCL_NONEXCLUSIVE);
	lpdimouse->SetDataFormat(&c_dfDIMouse);
	lpdimouse->Acquire();
	mstate=1;
	return 0;
}

int mcontrol()
{

	if (lpdimouse->GetDeviceState(sizeof(dimouse),&dimouse ) == DI_OK)
	{
		if (dimouse.rgbButtons[0]	& 0x80)
		{
			if (!clickhandle)
			{
				MessageBeep(0);
				clickhandle = TRUE;
			}
		}
		else
			clickhandle = FALSE;
		bx += dimouse.lX;
		by += dimouse.lY;
	}

	return 0;
}

int killmouse()
{
	// first unacquire the mouse

lpdimouse->Unacquire();

// now release the mouse

lpdimouse->Release();

// release directinput

lpdi->Release();
return 0;
}

void main()
{
	if (mstate==0)
	initcontrols();
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutCreateWindow("game engine console");
	glutReshapeFunc(ChangeSize);
	glutDisplayFunc(renderscene);
	setuprc();
	mcontrol();
	glutMainLoop();
	killmouse();
}

    

Share this post


Link to post
Share on other sites