驅動程式和應用程式交換事件物件

2021-07-04 06:52:05 字數 1427 閱讀 4849

exe部分**

#ifndef  ioctls_h

#define ioctls_h

#ifndef ctl_code

#pragma message("ctl_code undefined. include winioctl.h or ntddk.h")

#endif

//緩衝記憶體模式ioctl

#define ioctl_test1 ctl_code(file_device_unknown,0x800,method_buffered,file_any_access)

#endif

#include #include #include #include "ioctl.h"

dword threadproc( lpvoid lpparameter)

int main (void)

dword dwoutput=0;

//建立使用者模式同步事件

handle hevent=createevent(null,null,false,null);

handle hthread=createthread(null,null,(lpthread_start_routine)threadproc,&hevent,null,null);

if (deviceiocontrol(hdevice,ioctl_test1,&hevent,sizeof(hevent),null,null,&dwoutput,null))

waitforsingleobject(hthread,infinite);

printf("等待完畢over\n");

closehandle(hdevice);

getchar();

getchar();

return 0;

}

sys部分**

ntstatus helloddkcontrol(in pdevice_object pdevobj,in pirp pirp)

break;

default:

status=status_invalid_variant;

} //設定irp的完成狀態

pirp->iostatus.status=status;

pirp->iostatus.information=0;

iocompleterequest(pirp,io_no_increment);

return status;

}

/*

2023年8月2日 14:30:30

程式執行結果如下

執行緒執行中28

有訊號狀態,返回了。

ok等待完畢over

*/

驅動程式和應用程式通訊方法

驅動程式必須與應用程式進行通訊,才能最終達到應用程式控制裝置的目的,不然驅動有qiu用。要通訊就涉及到3個方面 1.應用程式與驅動程式通訊 2.驅動程式與應用程式通訊 3.資料傳輸 下面分別討論 1。應用程式與驅動程式通訊 1 1 應用程式實現與驅動通訊的過程 用createfile開啟裝置,用de...

驅動程式和應用程式之間通訊

正文 q 請問有什麼方法實現驅動程式主動和應用程式進行實時通訊,而不用應用程式採用定時查詢的方法?比如驅動有一事件發生需要立即通知應用程式,或驅動程式需要向應用程式讀取一些內容.a 有乙個很容易的方式,在驅動程式和應用程式之間用乙個事件。在應用程式createfile的時候,驅動程式iocreate...

驅動原理 應用程式訪問驅動程式

以read為例 read是乙個系統呼叫,系統呼叫之前在應用程式當中 或者叫使用者空間當中 read的實現 在核心中,read是如何找到核心的實現 呢?filename read mem.c include include include include intmain 這個應用程式就是開啟字元裝置檔...