And*_*dre 5 c windows driver wdf
我在Visual Studio 2013中编写了一个驱动程序.该构建过程是成功的.然后我准备了一个traget-computer并将驱动程序文件复制到它.然后我安装了驱动程序:
C:\Windows\system32>pnputil -a "E:\driverZeug\KmdfHelloWorldPackage\KmdfHelloWorld.inf"
Microsoft-PnP-Dienstprogramm
Verarbeitungsinf.: KmdfHelloWorld.inf
Das Treiberpaket wurde erfolgreich hinzugefügt.
Veröffentlichter Name: oem42.inf
Versuche gesamt: 1
Anzahl erfolgreicher Importe: 1
Run Code Online (Sandbox Code Playgroud)
看起来它很成功.我在PC上运行DebugView但现在我不知道如何启动驱动程序,以便我可以看到调试输出.我的源代码中有一个DbgPrintEx() - Statement.
有人能告诉我如何启动这个驱动程序,以便我可以看到输出.
这是驱动程序的源代码:
#include <ntddk.h>
#include <wdf.h>
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD KmdfHelloWorldEvtDeviceAdd;
NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
{
NTSTATUS status;
WDF_DRIVER_CONFIG config;
DbgPrintEx(DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n");
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: DriverEntry\n"));
WDF_DRIVER_CONFIG_INIT(&config, KmdfHelloWorldEvtDeviceAdd);
status = WdfDriverCreate(DriverObject, RegistryPath, WDF_NO_OBJECT_ATTRIBUTES, &config, WDF_NO_HANDLE);
return status;
}
NTSTATUS KmdfHelloWorldEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
{
NTSTATUS status;
WDFDEVICE hDevice;
UNREFERENCED_PARAMETER(Driver);
KdPrintEx((DPFLTR_IHVDRIVER_ID, DPFLTR_INFO_LEVEL, "KmdfHelloWorld: KmdfHelloWorldEvtDeviceAdd\n"));
status = WdfDeviceCreate(&DeviceInit, WDF_NO_OBJECT_ATTRIBUTES, &hDevice);
return status;
}
Run Code Online (Sandbox Code Playgroud)
如果安装已经完成,您需要制作一个EXE (testapp) 来启动您的驱动程序。您可以在应用程序中使用以下代码:
SC_HANDLE schService;
SC_HANDLE schSCManager;
schSCManager = OpenSCManager(NULL, // local machine
NULL, // local database
SC_MANAGER_ALL_ACCESS // access required
);
// Open the handle to the existing service.
schService = OpenService(SchSCManager,
DriverName, //name of the driver
SERVICE_ALL_ACCESS
);
StartService(schService, // service identifier
0, // number of arguments
NULL // pointer to arguments
));
Run Code Online (Sandbox Code Playgroud)
您需要根据您的需要添加代码。尝试这个。
有关详细信息,请下载 Microsoft 提供的示例驱动程序和测试应用程序。