Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 创建Windows驱动程序时出现链接错误_C++_Windows_Driver - Fatal编程技术网

C++ 创建Windows驱动程序时出现链接错误

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

我尝试创建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_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;
}
我在链接过程中遇到以下错误:

更多错误:

  • LNK2019函数“struct HINSTANCE*cdecl GetPdbDll(void)”中引用的未解析外部符号(?GetPdbDll@@YAPAUHINSTANCE@@XZ)\msvctd.lib(pdblkup.obj)

  • LNK2019函数“struct HINSTANCE*cdecl GetPdbDll(void)”中引用了未解析的外部符号(?GetPdbDll@@YAPAUHINSTANCE@@XZ)\msvctd.lib(pdblkup.obj)

  • LNK2019函数“struct HINSTANCE*cdecl GetPdbDll(void)”中引用的未解析外部符号(?GetPdbDll@@YAPAUHINSTANCE@@XZ)\msvctd.lib(pdblkup.obj)

  • LNK2019函数uu vsprintf_s_l\msvctd.lib(error.obj)中引用的未解析外部符号uuu stdio_common_vsprintf_

  • LNK2019未解析的外部符号uuu wsplitpath在函数“int uu cdecl GetPdbDllPathFromFilePath(wchar\t const*,wchar\u t*,unsigned int)”中引用(?GetPdbDllPathFromFilePath@@YAHPB\u WPA_WI@Z)\msvctd.lib(pdblkup.obj)

  • LNK2019未解析的外部符号\uuuuWmakePath在函数“int\uuuCDECL GetPdbDllPathFromFilePath(wchar\t const*,wchar\u t*,unsigned int)”中引用(?GetPdbDllPathFromFilePath@@YAHPB\u WPA_WI@Z)\msvctd.lib(pdblkup.obj)

  • LNK2019未解析的外部符号_@CmUnRegisterCallback@8在函数“void\uu fastcall RfUnload(struct\u DRIVER\u OBJECT*)”中引用(?RfUnload@@YIXPAU\u DRIVER\u OBJECT@@@Z)\DriverEntry.obj

  • LNK2019未解析的外部符号_@CmRegisterCallbackEx@24在函数中引用@DriverEntry@8\DriverEntry.obj

  • LNK2019未解析的外部符号uuuuuuuuuuuuuuuuuuuuuuuuuuuhandler4\msvcrd.lib(chandler4gs.obj)函数中引用的公共符号

  • LNK2019未解析的外部符号uuu CrtDbgReportW在函数uu CRT_RTC_INITW\msvctd.lib(init.obj)中引用

  • LNK2019未解析的外部符号_CrtDbgReport在函数_CRT_RTC_INIT\MSVCRTD.lib(INIT.obj)中引用

  • LNK2019未解析的外部符号在函数“int”中引用(?GetPdbDllPathFromFilePath@@YAHPB\u WPA_WI@Z)\msvctd.lib(pdblkup.obj)


  • 任何线索都会有帮助。

    可能的副本您需要使用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创建了“过滤器驱动程序:文件系统迷你过滤器”项目。我应该使用另一个模板吗?