阅读:1364回复:6
新手请教,简单问题
windows98下的VXD编程:
按书上教的,鼠标中断记数累加 Mouse.vxd //Mouse.h - include file for VxD Mouse #include <vtoolscp.h> #define DEVICE_CLASS MouseDevice #define MOUSE_DeviceID UNDEFINED_DEVICE_ID #define MOUSE_Init_Order UNDEFINED_INIT_ORDER #define MOUSE_Major 1 #define MOUSE_Minor 0 #define MY_IRQ 12 class MyHwInt:public VSharedHardwareInt { public: MyHwInt():VSharedHardwareInt(MY_IRQ, 0, 0, 0){} virtual BOOL OnSharedHardwareInt(VMHANDLE); }; class MouseDevice:public VDevice { public: virtual DWORD OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParam); }; //Mouse.cpp - main module for VxD Mouse #define DEVICE_MAIN #include \"mouse.h\" Declare_Virtual_Device(MOUSE) #undef DEVICE_MAIN #include \"apcx.h\" PVOID CallBackApc = 0; THREADHANDLE TheThread = 0; MyHwInt * pMyIRQ; int x = 0; BOOL MyHwInt::OnSharedHardwareInt(VMHANDLE hVM) { x++; VWIN32_QueueUserApc(CallBackApc, (DWORD)&x, TheThread); sendPhysicalEOI(); return FALSE; } DWORD MouseDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams) { switch (pDIOCParams->dioc_IOCtlCode) { case DIOC_OPEN: pMyIRQ = new MyHwInt(); if (!pMyIRQ || !pMyIRQ->hook()) return -1; return 0; case DIOC_CLOSEHANDLE: if (pMyIRQ) delete pMyIRQ; return 0; case ADDRPASS: CallBackApc = pDIOCParams->dioc_InBuf; TheThread = Get_Cur_Thread_Handle(); return 0; default: return -1; } } #MOUSE.mak - make fiel for VXD mouse DEVICENAME = MOUSE DYNAMIC = 1 FRAMEWORK = CPP DEBUG = 1 OBJECTS = mouse.obj !include $(VTOOLSD)\\include\\vtoolsd.mak !include $(VTOOLSD)\\include\\vxdtarg.mak mouse.obj: mouse.cpp mouse.h 然后应用程序是: #include <stdio.h> #include <windows.h> #include <winioctl.h> #include \"apcx.h\" DWORD WINAPI CallBackAPC(PVOID param) { printf(\"%d\\n\", *(int*)param); return 0; } void main() { HANDLE hDevice; hDevice = CreateFile(\"\\\\\\\\.\\\\Mouse.vxd\", 0, 0, 0, CREATE_NEW, FILE_FLAG_DELETE_ON_CLOSE, 0); if (hDevice = INVALID_HANDLE_VALUE) { fprintf(stderr, \"Cannot load VxD, error=%08ld\\n\", GetLastError()); exit(1); } if (!DeviceIoControl(hDevice, ADDRPASS, CallBackAPC, 0, 0, 0, 0, 0)) { fprintf(stderr, \"Failed to pass address\\n\"); exit(1); } printf(\"press Ctrl-C to exit...\\n\"); while(TRUE) SleepEx(INFINITE, TRUE); CloseHandle(hDevice); } 运行总是说不能加载vxd,错误00000002 我的机器的鼠标中断是12 高手指教呀,小弟初学,谢谢 |
|
沙发#
发布于:2002-10-11 15:03
2代表找不到你的vxd文件
在哪儿放着 多看看msdn :D |
|
|
板凳#
发布于:2002-10-11 15:26
可是明明就放在当前目录中呀,而且书上说2不一定就是指找不到vxd,有时不能加载也是2,而且我换成了静态的试了一下,vxdviewer中可以看到已经加载了,但应用程序还是说cannot load 00000002.....
|
|
地板#
发布于:2002-10-11 15:29
放到系统目录下去
c:\\windows\\sysytem :D |
|
|
地下室#
发布于:2002-10-11 15:33
放了是过了,不行的 :(
另外,我mouse.h和mouse.mak都不改 但是mouse.cpp中菜用win32事件编程,也就是用VWIN32_PulseWin32Event和OpenVxDHandle等唤醒应用程序第二个线程,就一切ok了,是不是98下的APC编程有什么特别的地方? |
|
5楼#
发布于:2002-10-11 15:37
放了是过了,不行的 :( 这我不态清楚,但这个和createfile有什么关系 |
|
|
6楼#
发布于:2002-10-11 15:47
就是说为什么采用APC方式时不行
而采用windows时间编程时就可以 |
|