创建Windows驱动程序

时间:2016-07-18 14:06:40

标签: c++ windows driver

我尝试创建一个Windows驱动程序:

.h文件:

NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2);
void RfUnload(__in PDRIVER_OBJECT pDriverObject);

.cpp文件:

#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;
}

我在LINK过程中遇到以下错误:

更多错误:

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

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

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

  4. LNK2019未解析的外部符号___stdio_common_vsprintf_s在函数__vsprintf_s_l \ MSVCRTD.lib中引用(错误 .obj)

  5. LNK2019未解析的外部符号__wsplitpath_s在函数“int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)”中引用“(?GetPdbDllPathFromFilePath @@ YAHPB_WPA_WI @ Z)\ MSVCRTD.lib( pdblkup .OBJ)

  6. LNK2019未解析的外部符号__wmakepath_s在函数“int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)”中引用“(?GetPdbDllPathFromFilePath @@ YAHPB_WPA_WI @ Z)\ MSVCRTD.lib( pdblkup .OBJ)

  7. LNK2019未解析的外部符号__imp_ @ CmUnRegisterCallback @ 8在函数“void __fastcall RfUnload(struct _DRIVER_OBJECT *)”中引用(?RfUnload @@ YIXPAU_DRIVER_OBJECT @@@ Z)\ DriverEntry.obj

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

  9. LNK2019未解析的外部符号__except_handler4_common在函数__except_handler4 \ MSVCRTD.lib中引用( chandler4gs .obj)

  10. LNK2019未解析的外部符号__CrtDbgReportW在函数__CRT_RTC_INITW \ MSVCRTD.lib( init .obj)中引用

  11. LNK2019未解析的外部符号__CrtDbgReport在函数__CRT_RTC_INIT \ MSVCRTD.lib( init .obj)中引用

  12. 在函数“int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)”(?GetPdbDllPathFromFilePath @@ YAHPB_WPA_WI @ Z)\ MSVCRTD.lib( pdblkup .OBJ)

  13. 任何线索都会有所帮助。

0 个答案:

没有答案