Original Post
Hello,
Ihave checked this through and I can''t see any errors, so here is my code. I get an access violation in GetInput Keyboard:
WPInput.h:
#define KEYDOWN(buf, key) (buf[key] & 0x80)
char KeyboardBuff[256];
#include
HINSTANCE DHInstance;
LPDIRECTINPUT lpDI;
HRESULT dival;
LPDIRECTINPUTDEVICE keyboard;
CreateInput(void)
{
DirectInputCreate(DHInstance, DIRECTINPUT_VERSION, &lpDI, NULL);
if(dival==DI_OK) { MessageBox(hWnd, "Input create worked", "HOORAY!", MB_OK);}
return 0;
}
CreateKeyboard(void)
{
dival=lpDI->CreateDevice(GUID_SysKeyboard, &keyboard, NULL);
return 0;
}
SetKeyboardFormat(void)
{
dival=keyboard->SetDataFormat(&c_dfDIKeyboard);
return 0;
}
SetCoopKeyboardNormal(void)
{
dival=keyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND/DISCL_NONEXCLUSIVE);
return 0;
}
GetInputKeyboard(void)
{
dival=keyboard->GetDeviceState(sizeof(KeyboardBuff), (LPVOID)&KeyboardBuff);
return 0;
}
AcquireKeyboard(void)
{
keyboard->Acquire();
return 0;
}
simple.cpp:
#include "WPWin.h"
#include "WPInput.h"
main(void)
{
CreateInput();
CreateKeyboard();
SetKeyboardFormat();
SetCoopKeyboardNormal();
AcquireKeyboard();
return 0;
}
/*----------------------------------------------------------------*\
Function: WindowProc();
Purpose: Handles window messages;
\*----------------------------------------------------------------*/
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch(msg) {
case WM_MOVE:
MessageBox(hWnd, "WM_MOVE: The Window Moved", TITLE, MB_OK);
return 0;
case WM_DESTROY:
MessageBox(hWnd, "WM_DESTROY: Exiting Application", "Goodbye!", MB_OK);
PostQuitMessage(0);
return 0;
}
GetInputKeyboard();
if (KEYDOWN(KeyboardBuff, DIK_LEFT))
{
MessageBox(hWnd, "hum", "Goodbye!", MB_OK);
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrev, LPSTR lpCmdLine, int Cmd)
{
StartRegWin();
wc.lpfnWndProc = WindowProcedure;
EndRegWin();
MakeWin();
if(hWnd==NULL) return FALSE;
else {
ShowWindow (hWnd, Cmd);
UpdateWindow(hWnd);
}
// Message loop;
while(GetMessage(&msg,NULL,0,0)) {
TranslateMessage(&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
WPWin.h:
#define WIN32_LEAN_AND_MEAN // Quicker build times;
#include
#define TITLE "WinCode"
HWND hWnd;
MSG msg;
WNDCLASS wc;
HINSTANCE hInstance;
int Cmd;
StartRegWin(void)
{
wc.style =CS_HREDRAW/CS_VREDRAW;
wc.cbClsExtra =0;
wc.cbWndExtra =0;
wc.hInstance =hInstance;
wc.hIcon =LoadIcon(hInstance,IDI_APPLICATION);
wc.hCursor =LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground =(HBRUSH)(COLOR_WINDOW+3);
wc.lpszMenuName =NULL;
wc.lpszClassName =TITLE;
return 0;
}
EndRegWin(void)
{
RegisterClass(&wc);
return 0;
}
MakeWin(void)
{
hWnd = CreateWindow(TITLE, // class name;
TITLE, // window name;
WS_OVERLAPPEDWINDOW, // window style;
CW_USEDEFAULT, CW_USEDEFAULT, // starting position (x,y);
320, 240, // width and height;
NULL, // parent handle;
NULL, // menu handle;
hInstance, // instance handle;
NULL); // other parameters;
// Check if window creation failed; otherwise show and update;
return 0;
}
I don''t belive the error is in WPWin.h because I''ve used it in code before and it worked fine.
I''m really sorry to bother you all, but you are, eyt again, my last hope,
Thanks,
Wilben.
Wilben
wilben@nerdy.freeserve.co.uk