Sign in to follow this  
snoddas14

DirecInput acting were wird, help needed!

Recommended Posts

hey i got this strange thing.... i complie it and it get no error, but then when i run it MsVs .net ends it and get´s me an break error! here is the code!
bool InputD3D(HINSTANCE hInst, HWND wndHandle)
{
	hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, 
		(void**)&din, NULL);
	if(FAILED(hr))
	{
		return FALSE;
	}
	hr = din->CreateDevice(GUID_SysKeyboard, &dinkey, NULL);
	if(FAILED(hr))
	{
		return FALSE;
	}

	hr =dinkey->SetDataFormat(&c_dfDIKeyboard);
	if(FAILED(hr))
	{
		return FALSE;
	}
	hr = dinkey->SetCooperativeLevel(wndHandle, DISCL_BACKGROUND);
	if(FAILED(hr))
	{
		return FALSE;
	}

	return TRUE;
}
void DInput(void)
{
	static BYTE keystate[256];
	dinkey->Acquire();
	dinkey->GetDeviceState(256, (LPVOID)keystate);
	if(keystate[DIK_W] &0x80)
		MessageBox(NULL,"W är ned tryckt?","You made it idot",MB_OK);

	return;

}

best regard Me.

Share this post


Link to post
Share on other sites
Quote:
Original post by snoddas14
i complie it and it get no error, but then when i run it
MsVs .net ends it and get´s me an break error!
Where? And what's the exact error? Are you using the debug runtimes? Any relevant debug output?

Share this post


Link to post
Share on other sites
I had a problem with this code yesterday too, the code


hr = DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8,
(void**)&din, NULL);



would always fail. I changed it to


hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8,
(void**)&din, NULL);



and it compiled and ran fine.

Hope this helps.

Share this post


Link to post
Share on other sites
hmm, i would i need a bit mor info to you guys.

when i komplie it i get no errors no warnings and one sucess!
but then when i runt it MSVS.net Breaks is and stop it and give me som sort of
"0x000000000 trying to get 0x000000005"
if i would be able to view a pictur of it, it would be easiyer!!

Share this post


Link to post
Share on other sites
Quote:
Original post by snoddas14
but then when i runt it MSVS.net Breaks is and stop it and give me som sort of
"0x000000000 trying to get 0x000000005"
Where? What line does it break on? That's a a sure sign of trying to dereference a null pointer, and the line it breaks on is the line with the null pointer. You can use the debugger to look at the values of your variables and find which one is null, then you can find out why it's null (If it wasn't set up correctly, or it was released / deleted).

Share this post


Link to post
Share on other sites

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