Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++ Timer and Forms?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Wed Aug 29, 2012 1:15 am    Post subject: C++ Timer and Forms? Reply with quote

Iv been messing with C++ for the past week but iv yet to get something working.

Im creating a blank dll project but i need to programmatically create a timer and populate a form.
SetTimer works but this isnt what im after.
Anyone know?

I made a version in C# that im trying to do the exact same thing in C++;
Looks like this and works fine. I know you'l be thinking why am i doing it like this. Why wouldnt i just create a thread and keep it open with a loop.
I have my reasons and this method works pefect for what i need, so bare with me.

DllMain
Code:
        public static int DllMain(String arg)
        {
            MakeTimer(HackTimer, 50);
            KeepAlive();
            return 0;
        }


The timer
Code:
        static void MakeTimer(EventHandler timed, int Intervals)
        {
            System.Windows.Forms.Timer TM = new System.Windows.Forms.Timer();
            TM.Interval = Intervals;
            TM.Start();
            TM.Tick += new EventHandler(timed);
        }


Form
Code:
        static void KeepAlive()
        {
            Form Fm = new Form();
            Fm.FormBorderStyle = FormBorderStyle.None;
            Fm.Size = new Size(0, 0);
            Fm.ShowInTaskbar = false;
            Fm.BackColor = Color.LimeGreen;
            Fm.TransparencyKey = Color.LimeGreen;
            Application.Run(Fm);
        }

_________________
Back to top
View user's profile Send private message
n0 m3rcY
Cheater
Reputation: 0

Joined: 18 Jun 2012
Posts: 42

PostPosted: Thu Aug 30, 2012 2:08 am    Post subject: Reply with quote

You could always just create a different thread in a loop and have a pointer to a boolean as a parameter, then just while(bool) loop with a sleep() at the end of the loop and kill the thread when you're done.
Back to top
View user's profile Send private message
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Thu Aug 30, 2012 6:06 am    Post subject: Reply with quote

Iv already tried this method. That works for a normal process but this process is killing the thread.

Creating a loop to force the thread to stay open is killed too. Well not killed but forces the process to close.

The timer method in my C# dll works perfect and doesnt get killed but i have no idea how to do the same in C++.

Iv tried SetTimer but that gets killed. Iv tried loading a form in the background with a timer but that gets killed.

In my C# dll, if i only create the timer, it gets killed but for some reason, creating a form after the timer keeps it open.

Im trying everything but the only method i know that works is in C# fudge.

_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25814
Location: The netherlands

PostPosted: Thu Aug 30, 2012 6:23 am    Post subject: Reply with quote

Have you tried spawning another thread from your thread, and in that newly spawned thread do everything and let the original one just die
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Thu Aug 30, 2012 11:00 am    Post subject: Reply with quote

Dark Byte wrote:
Have you tried spawning another thread from your thread, and in that newly spawned thread do everything and let the original one just die

Yea i tried that too, both threads die even with an inf loop. I thought that would work but same result.
The only thing that works so far is the method iv done in C#.

Im gonna do some reading and see if i can trick the process into thinking the thread was terminated.
Cause if i use an inf loop, the process knows this and terminates itself.
If i can fake the return value, maybe it'l stay open. Not sure if thats even possible but im gonna give it a go.

_________________
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25814
Location: The netherlands

PostPosted: Thu Aug 30, 2012 1:22 pm    Post subject: Reply with quote

Have you tried it in a process that isn't protected by nprotect?
If it also happens in another process, it might be because of a compiler optimization (you can turn that off, -O0)

And yes, nprotect has the habbit of destroying threads that haven't been registered properly

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Thu Aug 30, 2012 1:36 pm    Post subject: Reply with quote

Yea everything is tested on a normal process first, to make sure the code works.

I'v been at it for over a week now, i'll post a solution here if i ever come up with a working method.

_________________
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Aug 31, 2012 6:33 am    Post subject: Reply with quote

Given that you are using .NET components; the timer has to be created in a window. As said by MSDN:

http://msdn.microsoft.com/en-us/library/system.windows.forms.timer.aspx
Quote:

Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.


You don't want a timer for what you are doing, use the threading class instead:
http://msdn.microsoft.com/en-us/library/system.threading.thread.aspx



Overall is there really any reason you are using C++.NET at all?
All of this can be done without it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Pingo
Grandmaster Cheater
Reputation: 8

Joined: 12 Jul 2007
Posts: 571

PostPosted: Mon Sep 03, 2012 1:59 am    Post subject: Reply with quote

Just got back from a long weekend so sorry for the late reply.

No reason Wiccaan, im just trying anything.
I think i tried a threading class, cant remember. I'll go read over the docs you linked.

Yea i know the timer needs to be created in a window, i tried that too.

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites