0

我正在尝试找到SetProcessDEPPolicyWindows API 函数的地址kernel32请参阅我的问题here和我得到的第一个答案)。

我以前从未编写过 Windows C++ 程序,所以我有点迷茫,但到目前为止我有这个:

#include <windows.h>
#include <iostream>

int main(int argc, char* argv[])
{
    HANDLE kernel32 = GetModuleHandle("kernel32");
    FARPROC* funcAddr = (FARPROC *) GetProcAddress(kernel32, "SetProcessDEPPolicy");
    std::cout << "@ ";
}

我在第 7 行收到以下错误:

C:\Documents and Settings\John\Desktop>c++ finddep.cpp -o finddep.exe finddep.cpp: In function 'int main(int, char**)': finddep.cpp:7:79: error: invalid conversion from 'HANDLE {aka void*}' to 'HINSTA NCE' [-fpermissive]   FARPROC funcAddr = (FARPROC *) GetProcAddress(kernel32, "SetProcessDEPPolicy") ;
                                                                               ^
In file included from c:\mingw\include\windows.h:50:0,
from finddep.cpp:1: c:\mingw\include\winbase.h:1675:27: error:   initializing argument 1 of 'int (__ attribute__((__stdcall__)) * GetProcAddress(HINSTANCE, LPCSTR))()' [-fpermissive ]  WINBASEAPI FARPROC WINAPI GetProcAddress(HINSTANCE,LPCSTR);
^ finddep.cpp:7:79: error: cannot convert 'int (__attribute__((__stdcall__)) **)() ' to 'FARPROC {aka int (__attribute__((__stdcall__)) *)()}' in initialization   FARPROC funcAddr = (FARPROC *) GetProcAddress(kernel32, "SetProcessDEPPolicy") ;

我找不到任何关于如何从谷歌解决这个问题的好主意。

(一旦我得到这个编译,我怎么能打印指针中的地址?)

编辑:从评论中添加了 Cyclone 的建议,得到同样的错误Invalid conversion from HANDLE to HINSTANCE

4

1 回答 1

3

你应该这样做:

#include <windows.h>
#include <iostream>

int main(int argc, char* argv[])
{
    HMODULE kernel32 = GetModuleHandleA("kernel32");
    FARPROC *funcAddr = (FARPROC *)GetProcAddress(kernel32, "SetProcessDEPPolicy");
    std::cout << "@" << funcAddr;
}
于 2015-01-26T20:42:34.097 回答