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 


Calling a DialogBox from a DLL

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

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 14, 2008 4:01 pm    Post subject: Calling a DialogBox from a DLL Reply with quote

ok so i have a DLL that i made for Minesweeper, its only a small write 999 flags thing but anyways, it injects fine but once the dialog box opens up Minesweeper crashes.

help is appreciated.

Code:
#include <windows.h>
#include "resource.h"

BOOL bWantsExit = FALSE;

void WriteFlags()
{
   DWORD *pFlags = (DWORD*)0x1005194;
   *pFlags = 999;
}

DWORD WINAPI MonitorHotKeys()
{
   while ( !bWantsExit )
   {
      if ( GetAsyncKeyState( VK_F11 ) )
      {
         WriteFlags();
      }
      Sleep( 100 );
   }
   return 0;
}

BOOL CALLBACK DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
   case WM_INITDIALOG:
      CreateThread( NULL, NULL, (LPTHREAD_START_ROUTINE)MonitorHotKeys, NULL, NULL, NULL );
      return TRUE;

   case WM_COMMAND:
      switch( wParam )
      {
      case IDC_FLAGS:
         WriteFlags();
         return TRUE;
      }
      break;

   case WM_CLOSE:
      bWantsExit = TRUE;
      EndDialog( hWnd, 0 );
      return TRUE;

   case WM_DESTROY:
      bWantsExit = TRUE;
      PostQuitMessage( 0 );
      return TRUE;
   }
   return FALSE;
}


BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved )
{
   switch( dwReason )
   {
   case DLL_PROCESS_ATTACH:
      DisableThreadLibraryCalls( hModule );
      MessageBox( NULL, TEXT("Minesweeper DLL has been Injected Succesfully"), TEXT("DLL Injected"), MB_OK );
      DialogBox( hModule, MAKEINTRESOURCE( IDD_DIALOG1 ), NULL, (DLGPROC)DlgProc );
      return TRUE;
   case DLL_PROCESS_DETACH:
      bWantsExit = TRUE;
      return TRUE;
   }
   return TRUE;
}

_________________


Last edited by lurc on Mon Jan 14, 2008 4:13 pm; edited 1 time in total
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Jan 14, 2008 4:04 pm    Post subject: Reply with quote

You created a message loop in DllMain! LoadLibrary never returns! Don't use dangerous techniques like dll injection if you don't understand how they work!
_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 14, 2008 4:12 pm    Post subject: Reply with quote

lol oh >.< my bad i didnt know. no point in yelling, it was just a mistake.

so im sure its possible to call a dialogbox, id be neading a seperate thread my guess?

_________________
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Mon Jan 14, 2008 4:18 pm    Post subject: Reply with quote

Not recommended, don't do anything OTHER than initialization in DllMain. The safest way would be to make a function the dll exports that does the dialogbox, and have the injector use CreateRemoteThread to start a new thread there (the same way the injector uses CreateRemoteThread to call LoadLibrary).
_________________
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon Jan 14, 2008 4:33 pm    Post subject: Reply with quote

ok forget it, ill stick with making a dll with functions and just exporting them to a seperate executable.
_________________
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