Archived

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

Cant Set Cooperative Level...

This topic is 5047 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 have a keyboard class and it ALWYAS fails to set the cooperative level... (this is my init function, despite the slightly counter-intuitive name)
bool KEYBOARD::Get(HINSTANCE hInstance, HWND hWnd, LPDIRECTINPUT8 pDInput)
{
	if (pDInput)
	{
		KEYBOARD::pDInput = pDInput;
	}
	else
	{
		if (FAILED(DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void **)&(KEYBOARD::pDInput), NULL)))
			return FALSE;
	}

	if (FAILED(KEYBOARD::pDInput->CreateDevice(GUID_SysKeyboard, &(KEYBOARD::pDev), NULL)))
	{
		#ifndef __RELEASE___
		OutputDebugString("Failed to Create Keyboard device\n");
		#endif
		return FALSE;
	}

	if (FAILED(KEYBOARD::pDev->SetDataFormat(&c_dfDIKeyboard)))
	{
		#ifndef __RELEASE___
		OutputDebugString("Failed to set Keyboard Data Format\n");
		#endif
		return FALSE;
	}

	if (FAILED(KEYBOARD::pDev->Acquire()))
	{
		#ifndef __RELEASE___
		OutputDebugString("Failed to Acquire Keyboard device\n");
		#endif
		return FALSE;
	}

	if (FAILED(KEYBOARD::pDev->SetCooperativeLevel(hWnd, DISCL_FOREGROUND|DISCL_NONEXCLUSIVE)))
	{
		#ifndef __RELEASE___
		OutputDebugString("Failed to Set Keyboard Cooperative Level\n");
		#endif
		return FALSE;
	}

	return TRUE;
}
{/source]

thanx
-Dan

Share this post


Link to post
Share on other sites
I don''t think you can set the cooperative level while you''ve got the device aquired. Swap the Aquire and SetCooperativeLevel calls and see if that works.

By the way, the Debug Runtime should tell you why your call to SetCooperativeLevel is not working. Make sure you''re running the Debug Runtime with the Debug Output Level set to max. This will help you GREATLY when trying to debug your apps.

neneboricua

Share this post


Link to post
Share on other sites
Thanx a lot, the dumb book im using to learn all of dx didnt specify what order to do everythign in, so i just did some trial and error and did what worked, (which it did, but it just didnt set teh right cooperative level)
thanx
-Dan

Share this post


Link to post
Share on other sites