| View previous topic :: View next topic |
| Author |
Message |
Wintermoot Expert Cheater
Reputation: 0
Joined: 08 Nov 2007 Posts: 198
|
Posted: Fri Aug 08, 2008 9:51 am Post subject: C++ Help |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Aug 08, 2008 10:38 am Post subject: |
|
|
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 |
|
 |
Wintermoot Expert Cheater
Reputation: 0
Joined: 08 Nov 2007 Posts: 198
|
Posted: Fri Aug 08, 2008 7:20 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Aug 08, 2008 9:51 pm Post subject: |
|
|
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 |
|
 |
Zand Master Cheater
Reputation: 0
Joined: 21 Jul 2006 Posts: 424
|
Posted: Fri Aug 08, 2008 11:41 pm Post subject: |
|
|
| 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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Aug 08, 2008 11:44 pm Post subject: |
|
|
Yea but he only makes 1 check for 1, so if it isn't, it will just exit the thread.
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Aug 09, 2008 12:01 am Post subject: |
|
|
| 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 |
|
 |
Wintermoot Expert Cheater
Reputation: 0
Joined: 08 Nov 2007 Posts: 198
|
Posted: Sat Aug 09, 2008 3:41 am Post subject: |
|
|
| 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 |
|
 |
|