gpt4 book ai didi

c - NtFsControlFile函数错误

转载 作者:行者123 更新时间:2023-11-30 17:56:56 26 4
gpt4 key购买 nike

我有这个代码:

// page1.h

NTSTATUS (__stdcall *NtFsControlFile)(
HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG FsControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength
);


ULONG (__stdcall *RtlNtStatusToDosError) (
IN NTSTATUS Status
);

然后在page2.cpp:

page2.cpp
VOID LocateNativeEntryPoints()
{
//
// If we're on Win9x, just return
//
if( GetVersion() >= 0x80000000) return;

//
// Load the NTDLL entry point we need
//
if( !(NtFsControlFile = (void *) GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" )) ) {

_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
}
if( !(RtlNtStatusToDosError = (void *) GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"RtlNtStatusToDosError" )) ) {

_tprintf(TEXT("\nCould not find RtlNtStatusToDosError entry point in NTDLL.DLL\n"));
exit(1);
}
}

我在 if(!NtFsControlFile = 和 if( !(RtlNtStatusToDosError =,

error C2440: '=' : cannot convert from 'void *' to 'NTSTATUS (__stdcall *)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,ULONG,PVOID,ULONG,PVOID,ULONG)'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

error C2440: '=' : cannot convert from 'void *' to 'ULONG (__stdcall *)(NTSTATUS)'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast

原来的page2是C语言文件。我需要转换它以及如何做到这一点或者如何解决问题。

非常感谢。

似乎有效的解决方案(不像 C 语言那样自动转换):

     // a typedef to make casting easier

typedef NTSTATUS (__stdcall *NtFsControlFilePtr)(
HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG FsControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength);

// the actual pointer to function

NtFsControlFilePtr NtFsControlFile;

// and the GetProcAddress call

if( !(NtFsControlFile = reinterpret_cast<NtFsControlFilePtr>( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" ))) ) {

_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
}

此解决方案有效,但您会得到:

C4191:“reinterpret_cast”:不安全转换

与/WALL

避免警告:

if( !(NtFsControlFile = reinterpret_cast<NtFsControlFilePtr>( reinterpret_cast< void* >( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")), 
"NtFsControlFile" ))))) {

_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
}

if( !(RtlNtStatusToDosError = reinterpret_cast<RtlNtStatusToDosErrorPtr>( reinterpret_cast< void* >( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" ))))) {

_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
}

最佳答案

如果你有纯c代码,你可以稍微改变一下类型转换,我的意思是:

  1. 声明变量:

    typedef NTSTATUS (__stdcall *NT_FS_CONTROL_FILE)(IN HANDLE FileHandle,
    IN HANDLE Event, IN PIO_APC_ROUTINE ApcRoutine,
    IN PVOID ApcContext, OUT PIO_STATUS_BLOCKIoStatusBlock,
    IN ULONG FsControlCode, IN PVOID InputBuffer,
    IN ULONG InputBufferLength, OUT PVOID OutputBuffer,
    IN ULONG OutputBufferLength);
    NT_FS_CONTROL_FILE nt_fs_control_file;

    那么你需要

    nt_fs_control_file = GetProcAddress(

    nt_fs_control_file = (NT_FS_CONTROL_FILE)GetProcAddress
  2. 调用您的函数:

    NTSTATUS status = nt_fs_control_file(....);

关于c - NtFsControlFile函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13106131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com