我正在用c++编写一个程序,我有一个线程在使用.detach();当我尝试从它访问另一个线程时,调试器说响应已经优化出来了,我无法访问它。有什么办法可以“解决”吗?谢谢
这里有代码:
int foos;
unsigned int ReadProcess(HANDLE phandle, unsigned int address) {
unsigned int Pointer;
ReadProcessMemory(phandle, (void*)(address), &Pointer, sizeof(address), 0);
return Pointer;
}
void foo()
{
while (1) {
if (foos == 1) { break; }
volatile unsigned int xPointer, xBaseaddress = 0x002CF7DC, xoffset = 0x448, xoffset1 = 0x198, xoffset2 = 0x498, xoffset3 = 0x268, xoffset4 = 0x24;
HANDLE phandle = GetProcessHandle("Speed Calculator");
DWORD Base = (DWORD)GetBaseAddress(phandle);
xPointer = Base + xBaseaddress; //xPointer optimized out here
xPointer = ReadProcess(phandle, xPointer) + xoffset; //and here
xPointer = ReadProcess(phandle, xPointer) + xoffset1; //and here
xPointer = ReadProcess(phandle, xPointer) + xoffset2; //and here
xPointer = ReadProcess(phandle, xPointer) + xoffset3; //and here
xPointer = ReadProcess(phandle, xPointer) + xoffset4; //and here
if (!SendMessage(textBox1, WM_SETTEXT, NULL, (LPARAM)("IS: ") + xPointer))//and because of that, here
MessageBox(0, "Error: " + GetLastError(), "Error", MB_OK);
Sleep(299);
}
}
void main() {
foos = 0;
std::thread first(foo);
first.detach();
}我忽略了我的部分代码,因为它主要是一个win32 api交互。
发布于 2016-04-02 12:18:37
已使用参数调用编译器,要求对代码进行优化。
Visual示例
查看Visual中的解决方案配置(可以选择Release或Debug的下拉列表)。
如果您更改为Debug,则不应该对变量进行优化,您可以看到正在发生的事情。
更改解决方案配置时所发生的情况是,Visual在调用编译器时为该配置设置参数。在这种情况下,我们倾向于使用/Od (Disabled)标志来表示Configuration properties→C/C++→Optimization→Optimization,而不是/O2 (Maximize Speed)。
在调试期间,您还可以打开一个“线程”窗口来查看创建的线程。
https://stackoverflow.com/questions/36372877
复制相似问题