C++ handleProcess Error
C++ handleProcess Error
我一直在尝试编写一个c++内存编辑器,尽管我包含了#include <Windows.h>
库,但它仍然给了我一个错误"handleprocess未声明!"。下面是代码:
#include iostream
#include Windows.h
using namespace std;
int newScore;
int main()
{
HWND windowProgram = FindWindow(NULL,"Calculator");
cout << "Enter A new value to write:";
cin>>::newScore;
if(windowProgram == 0) {
cerr << "Unable To Locate Window" <<endl;
}else {
DWORD processID;
GetWindowThreadProcessId(windowProgram,&processID);
HANDLE handleProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,processID);
}
if(!handleProcess){
cerr << "Unable to handle process: " <<handleProcess<< " ! " << endl;
}else {
int memoryHack = WriteProcessMemory(
handleProcess,
(LPVOID)0XA18803B1CC,
&newScore,
(DWORD)sizeof(newScore),NULL);
if(memoryHack > 0){
clog<< " Memory Written" <<endl;
}else{
cerr<<"Failed to write to memory"<<endl;
}
CloseHandle(handleProcess);
}
cin.sync(),
cin.ignore();
return (0);
}
您需要在其他地方声明handleProcess
,以便在else
作用域之外可见。例如:
// ...
HANDLE handleProcess = 0; // Declare and initialize here.
if (windowProgram == 0) {
cerr << "Unable To Locate Window" <<endl;
} else {
DWORD processID;
GetWindowThreadProcessId(windowProgram, &processID);
handleProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
}
if (!handleProcess) {
// ...
注意,这不仅仅是标识符可见性问题。当退出作用域时,在堆栈上和作用域内创建的非静态变量将被销毁,并且不再存在。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- 对象声明中的模板"error: expected expression"
- 在C++中使用 Catch 测试框架编译错误"error: expected ';' at end of declaration list"
- OpenCV 3.4.1 error readNetFromTensorflow 无法在 cv::d nn::ReadProtoFromBinaryFile 中打开 .pb
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 为什么我会"error: expected expression"?
- CMake Error at modules/videoio/cmake/detect_ffmpeg.cmake:16
- 如果两个静态库使用相同的另一个静态库,如何避免"LNK2005 Already Defined error"?
- C++ handleProcess Error