• Advertisement
Sign in to follow this  

MFC project with DirectInput

This topic is 3496 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

I create a MFC project in VS2008. And I want to use DirectInput in this project. But I met a problem of Unepected error encountered when I SetCooperativeLevel in keyboard and mouse. Can MFC project use the DirectInput? I should use what value of SetCooperativeLevel for keyboard and mouse.
void DirectInput::DirectInputInit(HINSTANCE AppInstance,HWND hWnd)
{
	ZeroMemory(mKeyboardState, sizeof(mKeyboardState));
	ZeroMemory(&mMouseState, sizeof(mMouseState));

	HR(DirectInput8Create(AfxGetInstanceHandle(), DIRECTINPUT_VERSION, 
		IID_IDirectInput8, (void**)&mDInput, 0));

	HR(mDInput->CreateDevice(GUID_SysKeyboard, &mKeyboard, 0));
	HR(mKeyboard->SetDataFormat(&c_dfDIKeyboard));
	HR(mKeyboard->SetCooperativeLevel(m_hWnd, DISCL_NONEXCLUSIVE|DISCL_FOREGROUND));
	HR(mKeyboard->Acquire());

	HR(mDInput->CreateDevice(GUID_SysMouse, &mMouse, 0));
	HR(mMouse->SetDataFormat(&c_dfDIMouse2));
	HR(mMouse->SetCooperativeLevel(m_hWnd, DISCL_NONEXCLUSIVE|DISCL_FOREGROUND));
	HR(mMouse->Acquire());
}
[Edited by - akira32 on July 29, 2008 2:32:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement