While Statement Crash

My project crashes when I do this while statement to loop the value. I am looping the value because if it's not looped, the value will go to 0 instead of it staying the value (3084069) I want. How should I fix this?

1
2
3
4
5
private: System::Void checkBox1_CheckedChanged(System::Object^  sender, System::EventArgs^  e) {
while (checkBox1->Checked)
*(INT*)(
*(INT*)((INT)+0x7A97F0) + 0x55A8) = 3084069;
}
Last edited on
Looping what value? I don't see any values in there. What are you trying to do with this code?

As an aside, this doesn't look like C++. It looks like some kind of .NET language.
I am using Visual C++/CLI.
Looping what value? I don't see any values in there. What are you trying to do with this code?

If I had to guess, it looks like you're trying to write a number into a hardcoded memory location, which makes very little sense in this context.
Address: 0x7A97F0
Offset: 0x55A8
Value: 3084069
I am using this code to make a trainer for a game.
Last edited on
Typically, if a program crashes while you're writing a value into a memory address, it's because you're not allowed access to that memory. If that memory is part of a game, which is a different process, how are you getting permission to write into it?

Be aware that if something else is changing this value back to zero, and you're changing it to 3084069, in an endless switch-over, there's no guarantee that whatever reads the value will read your value rather than zero.
Last edited on
My project is a DLL. I can inject it into my game. When the I check the checkBox, it works, but my trainer crashes/becomes unresponsive. My other trainer works fine. I just need to know why my trainer crashes when I use the while statement. Is there an alternative way to make my value stay to 3084069?
Last edited on
Does it crash, or does it just stop responding? Big, big difference. If there's just one thread, then this while loop will run forever because the checkbox will never be unchecked.
It stops responding.
So when it's in this while loop, running this code forever, how are you expecting the state of the checkbox to change? For that to happen, some code somewhere must process an event and then set the value of the checkbox.
How should I change the state of the checkbox?
Should I do
 
while (checkBox1->Checked, checkBox1->CheckState->Checked);
Last edited on
No. You should have a thread in charge of the GUI containing the checkbox, and a thread in charge of running this while loop. The thread in charge of the GUI will keep the GUI responsive and process mouse events.

This is the common way that a GUI works; a principle thread in charge of displaying the GUI and responding to events, and separate threads for heavy processing.
I should use the CreateThread function right?
You're now way beyond a simple question and should step back to read about how to create and launch threads. This being the future, C++ has a thread library for you to use. I have no idea what .NET provides for you. CreateThread is a low-level Win32 function which you probably shouldn't be calling.
I don't get why I should create a thread just to end a loop.
The loop will end when checkBox1->Checked becomes false. If you are running a single thread, the following code is all the code that is executed, over and over, until checkBox1->Checked becomes false:

1
2
*(INT*)(
*(INT*)((INT)+0x7A97F0) + 0x55A8) = 3084069;


Does that code set checkBox1->Checked to false? No. So when will the loop end?
Last edited on
Okay so what I want to do is just freeze the value. If you know what cheat engine is you would know what I'm talking about. I want my value to stay at 3084069 forever, but my project becomes unresponsive whenever I tick the checkbox. However, the code is at 3084069 like I wanted it to be.
Last edited on
I don't need to know about cheat engines. Here is the situation:

Something else is setting that memory value to zero. You want to set it to 3084069 as fast as you can, over and over, so that it spends as little time as possible (ideally none) set to zero.

The way you're doing this is by having an infinite while loop that sets the value to 3084069 over and over.

Because this is an infinite while loop in a single-threaded program, no other code in your program will ever run once this while loop begins, so it won't respond to any input such as mouse-clicking over check-boxes.

If you're happy with this, great.

If you want to be able to uncheck that checkbox, you're going to have to have one thread in charge of this while loop, and a different thread in charge of keeping the GUI responsive and updating checkbox values.

This is how most GUI's work. One thread in charge of the event loop, keeping the GUI updated and responding to mouse clicks and other inputs, and any heavy processing done in separate threads.
Last edited on
Topic archived. No new replies allowed.