I try to create a Windows driver:
.h file:
NTSTATUS RfRegistryCallback(__in PVOID CallbackContext, __in PVOID Argument1, __in PVOID Argument2);
void RfUnload(__in PDRIVER_OBJECT pDriverObject);
.cpp file:
#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;
}
I get in the LINK process the following errors:
More errors:
LNK2019 unresolved external symbol _vcrt_LoadLibraryExW referenced in function "struct HINSTANCE * cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE@@XZ) \MSVCRTD.lib(pdblkup.obj)
LNK2019 unresolved external symbol _vcrt_GetModuleHandleW referenced in function "struct HINSTANCE * cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE@@XZ) \MSVCRTD.lib(pdblkup.obj)
LNK2019 unresolved external symbol _vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE * cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE@@XZ) \MSVCRTD.lib(pdblkup.obj)
LNK2019 unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l \MSVCRTD.lib(error.obj)
LNK2019 unresolved external symbol __wsplitpath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z) \MSVCRTD.lib(pdblkup.obj)
LNK2019 unresolved external symbol __wmakepath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z) \MSVCRTD.lib(pdblkup.obj)
LNK2019 unresolved external symbol __imp_@CmUnRegisterCallback@8 referenced in function "void __fastcall RfUnload(struct _DRIVER_OBJECT *)" (?RfUnload@@YIXPAU_DRIVER_OBJECT@@@Z) \DriverEntry.obj
LNK2019 unresolved external symbol __imp_@CmRegisterCallbackEx@24 referenced in function @DriverEntry@8 \DriverEntry.obj
LNK2019 unresolved external symbol __except_handler4_common referenced in function __except_handler4 \MSVCRTD.lib(chandler4gs.obj)
LNK2019 unresolved external symbol __CrtDbgReportW referenced in function __CRT_RTC_INITW \MSVCRTD.lib(init.obj)
LNK2019 unresolved external symbol __CrtDbgReport referenced in function __CRT_RTC_INIT \MSVCRTD.lib(init.obj)
LNK2019 unresolved external symbol _wcscpy_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z) \MSVCRTD.lib(pdblkup.obj)
Any clue will be helpful.