C++ 创建Windows驱动程序时出现链接错误
我尝试创建Windows驱动程序: .h文件:C++ 创建Windows驱动程序时出现链接错误,c++,windows,driver,C++,Windows,Driver,我尝试创建Windows驱动程序: .h文件: NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2); void RfUnload(__in PDRIVER_OBJECT pDriverObject); #include "Ntdef.h" #include "Ntddk.h" #include "DriverEntry.h" LARGE_INTE
NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2);
void RfUnload(__in PDRIVER_OBJECT pDriverObject);
#include "Ntdef.h"
#include "Ntddk.h"
#include "DriverEntry.h"
LARGE_INTEGER g_CmCookie = { 0 };
//--- Register ---//
extern "C"
NTSTATUS DriverEntry(__in PDRIVER_OBJECT pDriverObject, __in PUNICODE_STRING pRegistryPath)
{
UNREFERENCED_PARAMETER(pRegistryPath);
// Set up our unload routine
pDriverObject->DriverUnload = RfUnload;
// Register our callback with the system
UNICODE_STRING AltitudeString = RTL_CONSTANT_STRING(L"360000");
NTSTATUS status = CmRegisterCallbackEx(RfRegistryCallback, &AltitudeString, pDriverObject, NULL, &g_CmCookie, NULL);
if (!NT_SUCCESS(status))
{
// Failed to register - probably shouldn't succeed the driver intialization since this is critical
}
return status;
}
//--- Unregister ---//
void RfUnload(__in PDRIVER_OBJECT pDriverObject)
{
UNREFERENCED_PARAMETER(pDriverObject);
PAGED_CODE();
NTSTATUS status = CmUnRegisterCallback(g_CmCookie);
if (!NT_SUCCESS(status))
{
// Failed to unregister - try to handle gracefully
}
}
//--- Callback handle
NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2)
{
UNREFERENCED_PARAMETER(CallbackContext);
UNREFERENCED_PARAMETER(Argument2);
REG_NOTIFY_CLASS Operation = (REG_NOTIFY_CLASS)(ULONG_PTR)Argument1;
switch (Operation)
{
.....
}
return STATUS_SUCCESS;
}
.cpp文件:
NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2);
void RfUnload(__in PDRIVER_OBJECT pDriverObject);
#include "Ntdef.h"
#include "Ntddk.h"
#include "DriverEntry.h"
LARGE_INTEGER g_CmCookie = { 0 };
//--- Register ---//
extern "C"
NTSTATUS DriverEntry(__in PDRIVER_OBJECT pDriverObject, __in PUNICODE_STRING pRegistryPath)
{
UNREFERENCED_PARAMETER(pRegistryPath);
// Set up our unload routine
pDriverObject->DriverUnload = RfUnload;
// Register our callback with the system
UNICODE_STRING AltitudeString = RTL_CONSTANT_STRING(L"360000");
NTSTATUS status = CmRegisterCallbackEx(RfRegistryCallback, &AltitudeString, pDriverObject, NULL, &g_CmCookie, NULL);
if (!NT_SUCCESS(status))
{
// Failed to register - probably shouldn't succeed the driver intialization since this is critical
}
return status;
}
//--- Unregister ---//
void RfUnload(__in PDRIVER_OBJECT pDriverObject)
{
UNREFERENCED_PARAMETER(pDriverObject);
PAGED_CODE();
NTSTATUS status = CmUnRegisterCallback(g_CmCookie);
if (!NT_SUCCESS(status))
{
// Failed to unregister - try to handle gracefully
}
}
//--- Callback handle
NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2)
{
UNREFERENCED_PARAMETER(CallbackContext);
UNREFERENCED_PARAMETER(Argument2);
REG_NOTIFY_CLASS Operation = (REG_NOTIFY_CLASS)(ULONG_PTR)Argument1;
switch (Operation)
{
.....
}
return STATUS_SUCCESS;
}
我在链接过程中遇到以下错误:
更多错误:
任何线索都会有帮助。可能的副本您需要使用hal.lib进行\uu imp__KeGetCurrentIrql@0和/NODEFAULTLIB选项,用于不与msvcrt[d]链接。lib还有更多错误:您不需要包含ntdef.h,ntddk.h(或ntifs.h)执行此任务。似乎还包括了一些仅适用于用户模式应用程序的内容。您是如何创建驱动程序项目的?MS Visual Studio(2012+)的最新版本有相应的模板,或者您可以使用VisualDDK(MSVS 2010),尽管这不是最干净的方式。我使用VS2015创建了“过滤器驱动程序:文件系统迷你过滤器”项目。我应该使用另一个模板吗?可能重复的模板需要使用hal.lib for _imp__KeGetCurrentIrql@0和/NODEFAULTLIB选项,用于不与msvcrt[d]链接。lib还有更多错误:您不需要包含ntdef.h,ntddk.h(或ntifs.h)执行此任务。似乎还包括了一些仅适用于用户模式应用程序的内容。您是如何创建驱动程序项目的?MS Visual Studio(2012+)的最新版本有相应的模板,或者您可以使用VisualDDK(MSVS 2010),尽管这不是最干净的方式。我使用VS2015创建了“过滤器驱动程序:文件系统迷你过滤器”项目。我应该使用另一个模板吗?