我在创建直接输入时遇到错误。我不断收到自己的错误信息,无法创建直接输入。
void dInputs::CreatedInputs(HINSTANCE hInstance)
{
HRESULT hr;
hr = DirectInput8Create(hInstance, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&di_Object, NULL);
hr = di_Object->CreateDevice(GUID_SysKeyboard, &di_KeyboardDevice, NULL);
hr = di_KeyboardDevice->SetDataFormat(&c_dfDIKeyboard);
hr = di_KeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
if(FAILED(hr))
{
MessageBox(NULL,"Failed to create Direct Input","Error",MB_OK);
}
UsingD_Input();
}
我测试了每个hresult,错误来自这里的行,因为我正在使用我的Base标头中的hWnd。有什么想法来解决它吗?
hr = di_KeyboardDevice->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
这是我的input.h
#pragma once
#ifndef DINPUTS_H
#define DINPUTS_H
#define DIRECTINPUT_VERSION 0x0800
#include "Base.h"
#include <dinput.h>
class dInputs : public Base
{
LPDIRECTINPUT8 di_Object;
LPDIRECTINPUTDEVICE8 di_KeyboardDevice;
BYTE keys[256];
public:
dInputs(void);
void CreatedInputs(HINSTANCE hInstance);
void UsingD_Input();
int GetInput();
void ReleaseDInputs();
~dInputs(void);
};
#endif
这是我的base.h
#pragma once
#ifndef BASE_H
#define BASE_H
#include <Windows.h>
#include <windowsx.h>
class Base
{
WNDCLASSEX WndCls;
HRESULT Hr;
public:
HWND hWnd;
Base();
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
void RegisterWnd(HINSTANCE hInstance);
void ShowWnd(int nCmdShow);
void RunWnd(HINSTANCE hInstance, int nCmdShow);
~Base();
};
#endif
如果我的解释不够明确,我很抱歉。尽可能多地学习c ++编程。请提供更多关于我的错误的解释。谢谢