这一篇主要说明应用程序怎么去和驱动程序通信的,包括识别打开驱动程序,传递数据到驱动程序,同时接收驱动程序返回的数据。
application.c
- 首先是应用程序的创建,WDF里利用模板生成驱动程序时时不带有应用程序的源文件的,需要我们自己手动生成,其实就是和创建一个C语言文件一样。找到驱动程序的解决方案,右键选择‘添加’->‘新建项目’->‘测试’->‘Applications’,选择第一个就行了,保存时注意存为.c文件,因为整个项目都是C来写的,没有用C++。需要注意的就是这个文件一定要在驱动程序的那个解决方案下才行,然后在该项目的项目依赖项里勾选上你的驱动程序,表示它是依赖于驱动程序才有用的。
2.代码
/*++
Module Name: application.c
Abstract:This file contains application which communicates with driversoft, including main and GetDevicePath function.
Environment: User-mode Driver Framework
Time: 20181015
--*/
#include <windows.h>
#include <winioctl.h>
#include <setupapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include "tchar.h"
#include "../PCIe/Public.h"
HANDLE hDevice = INVALID_HANDLE_VALUE;
PCHAR GetDevicePath(IN LPGUID InterfaceGuid);
int _tmain(int argc, _TCHAR* argv[])
{
PCHAR DevicePath;
ULONG nOutput;
//LPDWORD count = 0;
UNREFERENCED_PARAMETER(argc);
UNREFERENCED_PARAMETER(argv);
printf("Application control test starting...\n");
//利用GUID号找到设备路径
DevicePath = GetDevicePath((LPGUID)&GUID_DEVINTERFACE_PCIe);
if (DevicePath == 0)
{
printf("ERROR: Get DevicePath failed! ErrNo:%0x\n"