c++ - GetProcessDEPPolicy 错误 87

标签 c++ windows winapi visual-c++ visual-studio-2015

当我尝试检查某个进程是否正在使用数据执行保护 (DEP) 时,我收到错误 87 (INVALID_PARAMETER)。我检查了我的代码,它似乎没问题,但不幸的是我仍然有同样的错误。

代码:

BOOL var = true;
DWORD dwPolicy;

HANDLE hProc = OpenProcess(PROCESS_QUERY_INFORMATION, false, 3624);
if (hProc == NULL) {
    cout << "Can't open Process because of the error " << GetLastError() << endl;
}

if (GetProcessDEPPolicy(hProc, &dwPolicy, 0) != FALSE) {
    if (dwPolicy == PROCESS_DEP_ENABLE) {
        cout << "For try.exe process data execution prevention is enabled" << endl;

    }
    else if (dwPolicy == NULL) {
        cout << "For try.exe process data execution prevention is disabled" << endl;
    }
    else {
        cout << "Data is thrunked and we can't change DEP value in future" << endl;
    }
}
else {
    cout << "There was an error with discovering DEP in try.exe process because of "<<GetLastError() << endl;
}

编译执行后得到:

There was an error with discovering DEP in try.exe process because of 87

最佳答案

查看文档,函数GetProcessDEPPolicy定义:

BOOL WINAPI GetProcessDEPPolicy(
  _In_  HANDLE  hProcess,
  _Out_ LPDWORD lpFlags,
  _Out_ PBOOL   lpPermanent
);

请注意,最后一个参数是一个输出参数,它不是可选的,但您传递的是 0,也就是 NULL。调用应该是:

BOOL permanent = FALSE;
if (GetProcessDEPPolicy(hProc, &dwPolicy, &permanent) != FALSE) {

关于c++ - GetProcessDEPPolicy 错误 87,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37889449/

相关文章:

python - 无法在 Windows cmd 中添加 Python

c# - 如何获取长路径的安全详细信息?

c++ - for 循环初始化语句中的未命名结构声明

c++ - 如何将二进制文件的十六进制表示形式保存到 std::string 中?

windows - 在命令提示符下运行程序的双命令

c++ - 将项目添加到 ListView?

windows - WinAPI Shell API 与基本 API 和 CRT 函数有何不同?

windows - 使用未记录的 CallNtPowerInformation(GetPowerRequestList..) 枚举 Windows "Power Availability Requests"

c++ - 参数是对文字类型的引用时的常量函数

c++ - gcc - 在一个命令中链接和编译