阅读:1380回复:4
怎样从驱动程序中获得数据?
我做了一块板卡,需要用到中断。做了一个VXD中断驱动程序,当中断产生时读I/O端口数据。在C++下读出了数据。但是我对VC做界面不熟悉,想用VB做界面。问题是我在VB下怎样获得数据?急呀,各位帮帮忙。感激!!!!!!!!!
用vtoolsd做了驱动程序,如下: // 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 9 class MyHwInt: public VHardwareInt { public: MyHwInt():VHardwareInt(MY_IRQ,0,0,0){} virtual VOID OnHardwareInt(VMHANDLE); }; class MouseDevice : public VDevice { public: virtual BOOL OnSysDynamicDeviceInit(); virtual BOOL OnSysDynamicDeviceExit(); virtual DWORD OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams); }; // MOUSE.cpp - main module for VxD MOUSE #define DEVICE_MAIN #include \"mouse.h\" Declare_Virtual_Device(MOUSE) #undef DEVICE_MAIN #include\"apcx.h\" MyHwInt *pMyIRQ; PVOID CallBackApc=0; THREADHANDLE TheThread=0; int x; VOID MyHwInt::OnHardwareInt(VMHANDLE hVM) { x++; VWIN32_QueueUserApc(CallBackApc,(DWORD)&x,TheThread); sendPhysicalEOI(); } BOOL MouseDevice::OnSysDynamicDeviceInit() { pMyIRQ=new MyHwInt(); if(!pMyIRQ||!pMyIRQ->hook()) { return FALSE; } else { pMyIRQ->physicalUnmask(); return TRUE; } } BOOL MouseDevice::OnSysDynamicDeviceExit() { if(pMyIRQ) delete pMyIRQ; return TRUE; } DWORD MouseDevice::OnW32DeviceIoControl(PIOCTLPARAMS pDIOCParams) { switch(pDIOCParams->dioc_IOCtlCode) { case DIOC_OPEN: return 0; case DIOC_CLOSEHANDLE: return 0; case ADDRPASS: CallBackApc=pDIOCParams->dioc_InBuf; TheThread=Get_Cur_Thread_Handle(); return 0; default: return -1; } } 在VC下调用驱动程序编程如下: 我怎样将 int_cnt 和 result传给VB? #include<stdio.h> #include<windows.h> #include<winioctl.h> #include\"apcx.h\" #include<conio.h> unsigned int result; int int_cnt; DWORD WINAPI CallBackAPC(PVOID param) { int_cnt=*(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=%d\\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); result=_inp(0x301); printf(\"中断次数=%d\\n\",int_cnt); printf(\"端口读数=%d\\n\",result); } CloseHandle(hDevice); } [编辑 - 10/7/02 by fangrui] |
|
沙发#
发布于:2002-10-08 12:51
用VC做个dll,得到数据
VB做界面,调VC的那个dll |
|
板凳#
发布于:2002-10-08 15:20
谢谢楼上的老兄,这个DLL怎么做,能给我说的详细一点吗?VB中怎么启动这个DLL使中断VXD处于等待状态以捕获中断?谢谢!
|
|
地板#
发布于:2002-10-08 15:44
dll还不好做
用vc向导生成一个框架,然后把你的导出函数加到框架中去,编译通过后生成dll文件 再用vb调用dll中的函数就ok了 :D |
|
|
地下室#
发布于:2002-10-08 17:54
问题是:这种带中断的DLL怎么做?怎么在启动VB的程序时就调入中断程序,使其处于等待状态,等待中断的产生并返回值?
|
|