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++ Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Wintermoot
Expert Cheater
Reputation: 0

Joined: 08 Nov 2007
Posts: 198

PostPosted: Fri Aug 08, 2008 9:51 am    Post subject: C++ Help Reply with quote

I don't get any errors, It's just that it never prints "Hello World"...
This is a DLL... I know that using CreateThread is bad but, it is going to be having a few loops in it and we don't want things locking up...
I am still learning C++ so, please don't bitch about my bad coding... I came from VB and Delphi...

Code:
DWORD WINAPI MainLoop(LPVOID lpParam)
{
   int LOOL=0;
   std::cout << "Hello World!";
   std::cin >> LOOL;
   if ( LOOL == 1 )
   {
      FreeConsole();
   }
   return 0;
}

bool WINAPI DllMain(HMODULE hInst, DWORD reason, LPVOID reserved)
{
   switch (reason)
    {
      case DLL_PROCESS_ATTACH:
        AllocConsole(); // Creates a console
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)MainLoop, NULL, 0, NULL);


      case DLL_PROCESS_DETACH:
        break;

   }
   return TRUE;
}
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Aug 08, 2008 10:38 am    Post subject: Reply with quote

1. Break after CreateThread.
2. cout won't work when you use AllocConsole();

Using AllocConsole() you have to get the screen buffer and call WriteConsole/ReadConsole.

Take a look at this:
http://msdn.microsoft.com/en-us/library/ms685035.aspx

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

Joined: 08 Nov 2007
Posts: 198

PostPosted: Fri Aug 08, 2008 7:20 pm    Post subject: Reply with quote

Thank you lurc and Fuzz and spawn and Zand (Sorry if I don''t mention you, it was 3 AM...)

Last edited by Wintermoot on Fri Aug 08, 2008 10:56 pm; edited 1 time in total
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 08, 2008 9:51 pm    Post subject: Reply with quote

Just a said note, your thread function doesn't actually loop so the console is never freed using FreeConsole(); Instead, it just returns.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Zand
Master Cheater
Reputation: 0

Joined: 21 Jul 2006
Posts: 424

PostPosted: Fri Aug 08, 2008 11:41 pm    Post subject: Reply with quote

Wiccaan wrote:
Just a said note, your thread function doesn't actually loop so the console is never freed using FreeConsole(); Instead, it just returns.


Doesn't std::cin make it pause for input?
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Aug 08, 2008 11:44 pm    Post subject: Reply with quote

Yea but he only makes 1 check for 1, so if it isn't, it will just exit the thread.
_________________
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: Sat Aug 09, 2008 12:01 am    Post subject: Reply with quote

Zand wrote:
Wiccaan wrote:
Just a said note, your thread function doesn't actually loop so the console is never freed using FreeConsole(); Instead, it just returns.


Doesn't std::cin make it pause for input?


Yeah but relook at the code. Like Lurc pointed out, it will only check once then exit the thread. It's misleading for it to be called a loop as it never loops anything.

Something a little more to the point would be:

Code:
void WINAPI MainLoop( LPVOID lpReserved )
{
   for( ;; )
   {
      // Hotkey to tell thread to exit..
      if( GetAsyncKeyState( VK_F4 )&1 )
         break;

      Sleep( 10 );
   }
   FreeConsole();
   FreeLibraryAndExitThread( hThreadHandle, 0 );
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Wintermoot
Expert Cheater
Reputation: 0

Joined: 08 Nov 2007
Posts: 198

PostPosted: Sat Aug 09, 2008 3:41 am    Post subject: Reply with quote

Please note, this is just the hacked up code I got from slowly commenting things out... I do make it loop and everything, I just didn't post it because, it was not necessary... I think that lurc may have given me the answer... When I can be bothered to read and understand it all. (In other words, when I can be bothered ripping the code I need...)
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