阅读:1678回复:4
为什么一调用DeviceIoControl()就会死机
我作一个DLL与VXD通信但每次执行到DeviceIoControl()时就会死机,相关类似的代码我用一般应用程序试过,没有问题,但为什么在DLL中不能用。
出错时变成黑屏提示如下: windows protection error,you need to restart your computer 具体程序如下: #include <stdio.h> #include <conio.h> #include <windows.h> #include <winioctl.h> #include \"LinkVXD.h\" #pragma pack(1) HANDLE hDevice; int i; int x; DWORD WINAPI SecondThread(PVOID hEventRing3) { while(TRUE) { WaitForSingleObject(hEventRing3,INFINITE); DeviceIoControl(hDevice,READ,0,0,&i,0,0,0); printf(\"%d\\n\", i); } return 0; } unsigned short __declspec(dllexport) LinkVXD(LONG NNN) { HANDLE hEventRing3,hEventRing0; HMODULE hKernel32Dll; DWORD tid; x=1; HANDLE (WINAPI *pfOpenVxDHandle)(HANDLE); hEventRing3=CreateEvent(0,FALSE,FALSE,NULL); if (!hEventRing3) { fprintf(stderr,\"Failed to create event3...\\n\"); exit(1); } hKernel32Dll=LoadLibrary(\"kernel32.dll\"); if (!hKernel32Dll) { fprintf(stderr, \"Failed to load...\\n\"); exit(1); } pfOpenVxDHandle=(HANDLE(WINAPI *)(HANDLE))GetProcAddress(hKernel32Dll,\"OpenVxDHandle\"); if (!pfOpenVxDHandle) { fprintf(stderr, \"Failed to get...\\n\"); exit(1); } hEventRing0=(HANDLE)(*pfOpenVxDHandle)(hEventRing3); if (!hEventRing0) { fprintf(stderr, \"Failed to get hEventRing0...\\n\"); exit(1); } hDevice=CreateFile(\"\\\\\\\\.\\\\MOUSE.VXD\",0,0,0,CREATE_NEW,FILE_FLAG_DELETE_ON_CLOSE,0); if (hDevice == INVALID_HANDLE_VALUE) { return 1; } MessageBox(NULL,\"sdfsdfsfs\",\"3\",MB_OK); if ( !DeviceIoControl(hDevice,hEventPASS,hEventRing0,0,0,0,0,0)) { MessageBox(NULL,\"sdfsdfsfs\",\"2\",MB_OK); fprintf(stderr, \"Failed to pass hEvent...\\n\"); exit(1); } MessageBox(NULL,\"sdfsdfsfs\",\"4\",MB_OK); CreateThread(0,0x1000,SecondThread,hEventRing3,0,&tid); // printf(\"press any key to exit . . .\\n\"); // getch(); // while(x) // {;} CloseHandle(hDevice); return 0; } |
|
|
沙发#
发布于:2002-06-25 08:35
各位帮忙呀
|
|
|
板凳#
发布于:2002-06-25 08:52
我作一个DLL与VXD通信但每次执行到DeviceIoControl()时就会死机,相关类似的代码我用一般应用程序试过,没有问题,但为什么在DLL中不能用。 怎么你的deviceiocontrol的参数的length都0!当然不对。 |
|
地板#
发布于:2002-06-25 08:56
那个deviceiocontrol死机
|
|
|
地下室#
发布于:2002-06-25 08:59
看看deviceiocontrol的函数原型
|
|
|