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++] GUI/DLL help
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Drops
Advanced Cheater
Reputation: 0

Joined: 22 Feb 2008
Posts: 62

PostPosted: Tue Jun 24, 2008 6:31 pm    Post subject: [C++] GUI/DLL help Reply with quote

Hi,
I remember this trainer in the maplestory section (irrelevant) that was a gui in dll form. How is it that you can do that with pure win32 api? I tried something like upon DLL_PROCESS_ATTACH, createthread for WinMain, but I tried injecting it into notepad and no window came up Sad

Any help is appreciated!

Thanks,
Drops.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Tue Jun 24, 2008 6:35 pm    Post subject: Reply with quote

Can we see your code?
_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Drops
Advanced Cheater
Reputation: 0

Joined: 22 Feb 2008
Posts: 62

PostPosted: Tue Jun 24, 2008 6:38 pm    Post subject: Reply with quote

oib111 wrote:
Can we see your code?


Code:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
   switch(ul_reason_for_call)
   {
   case DLL_PROCESS_ATTACH:
      CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)WinMain,NULL,0,NULL);
      break;
   default:
      ;
   }
   return TRUE;
}

const char g_szClassName[] = "myWindowClass";
HBRUSH g_hbrBackground = CreateSolidBrush(RGB(0,0,0));

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
   switch(msg)
   {
   case WM_CLOSE:
      DestroyWindow(hwnd);
   break;

   case WM_DESTROY:
      PostQuitMessage(0);
   break;

   default:
      return DefWindowProc(hwnd, msg, wParam, lParam);
   }
   return 0;
}

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
   WNDCLASSEX wc;
   HWND hwnd;
   MSG Msg;
   HBRUSH bgColor = CreateSolidBrush(RGB(0,0,0));

   wc.cbSize = sizeof(WNDCLASSEX);
   wc.style = 0;
   wc.lpfnWndProc = WndProc;
   wc.cbClsExtra = 0;
   wc.cbWndExtra = 0;
   wc.hInstance = hInstance;
   wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
   wc.hCursor = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)bgColor;
//   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName = NULL;
   wc.lpszClassName = g_szClassName;
   wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

   if(!RegisterClassEx(&wc))
   {
      MessageBox(NULL,"Window Registration Failed!", "Error", MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   hwnd = CreateWindowEx(WS_EX_CLIENTEDGE|WS_EX_APPWINDOW, g_szClassName, "Trainer", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 250, 250, NULL, NULL, hInstance, NULL);

   if(hwnd == NULL)
   {
      MessageBox(NULL, "Window Creation Failed!", "Error", MB_ICONEXCLAMATION | MB_OK);
      return 0;
   }

   ShowWindow(hwnd, nCmdShow);
   UpdateWindow(hwnd);

   while(GetMessage(&Msg, NULL, 0, 0) > 0)
   {
      TranslateMessage(&Msg);
      DispatchMessage(&Msg);
   }
   return Msg.wParam;
}


I'm just testing if I can do this first before making the whole gui, so it's just a window right now. If I make it as an exe it works just fine.
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Jun 24, 2008 6:40 pm    Post subject: Reply with quote

on DLL_PROCESS_ATTACH simply create a thread that initializes a window.

You can either use pure Win32 API such as WNDCLASSEX struct, RegisterClassEx, CreateWindowEx, etc.

Or you can make dialog's through resource's and just call DialogBox.

Don't use WinMain, that is the entry point to a Windows Application.

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

Joined: 22 Feb 2008
Posts: 62

PostPosted: Tue Jun 24, 2008 6:53 pm    Post subject: Reply with quote

lurc wrote:
on DLL_PROCESS_ATTACH simply create a thread that initializes a window.

You can either use pure Win32 API such as WNDCLASSEX struct, RegisterClassEx, CreateWindowEx, etc.

Or you can make dialog's through resource's and just call DialogBox.

Don't use WinMain, that is the entry point to a Windows Application.


Whew! Thanks!

Just a question: I changed the function parameters to just LPVOID lpParam, but then I don't have hInstance, so I just set all the functions that needed it to NULL (I also just changed ShowWindow(hwnd,nCmdShow) to ShowWindow(hwnd,SW_SHOW), but I don't think that will change anything). Will setting the hInstance to NULL affect anything? If so, how can I get the hInstance? (it works fine when injected if I just have NULL)
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue Jun 24, 2008 6:57 pm    Post subject: Reply with quote

ShowWindow with the SW_SHOW is needed because nCmdShow doesn't exist.

Get the hInstance with GetModuleHandle:
Code:
HINSTANCE hInstance = GetModuleHandle( NULL );

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

Joined: 22 Feb 2008
Posts: 62

PostPosted: Tue Jun 24, 2008 7:11 pm    Post subject: Reply with quote

lurc wrote:
ShowWindow with the SW_SHOW is needed because nCmdShow doesn't exist.

Get the hInstance with GetModuleHandle:
Code:
HINSTANCE hInstance = GetModuleHandle( NULL );


What would happen if I had just put NULL though? Like future problems, possible errors, etc o-o Just wanna know =/
Back to top
View user's profile Send private message
STN
I post too much
Reputation: 43

Joined: 09 Nov 2005
Posts: 2676

PostPosted: Wed Jun 25, 2008 5:41 am    Post subject: Reply with quote

lurc wrote:
ShowWindow with the SW_SHOW is needed because nCmdShow doesn't exist.


It DOES exist and passing SW_SHOW isn't necessary. Passing nCmdShow(in the WinMain aswell) means giving permission to whoever is running your program to specify whether or not they want your window to start off visible, maximized, minimized.

Quote:
What would happen if I had just put NULL though? Like future problems, possible errors, etc o-o Just wanna know =/


Putting NULL in GetModuleHandle() ?. It will return the hInstance of the calling process.

_________________
Cheat Requests/Tables- Fearless Cheat Engine
https://fearlessrevolution.com
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Wed Jun 25, 2008 6:52 am    Post subject: Reply with quote

Yes, GetModuleHandle(NULL) returns the hInstance of the process.
The hInstance of the dll that's injected is passed to DllMain I believe. (you've called it hModule in you're code)
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jun 25, 2008 8:59 am    Post subject: Reply with quote

STN wrote:
lurc wrote:
ShowWindow with the SW_SHOW is needed because nCmdShow doesn't exist.


It DOES exist and passing SW_SHOW isn't necessary. Passing nCmdShow(in the WinMain aswell) means giving permission to whoever is running your program to specify whether or not they want your window to start off visible, maximized, minimized.


I didn't mean that nCmdShow didn't exist in the WinMain function, because i know it exists there. But within a DLL you don't use WinMain, so the parameter doesn't exist.

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

Joined: 22 Feb 2008
Posts: 62

PostPosted: Wed Jun 25, 2008 10:37 am    Post subject: Reply with quote

Hey,
I'm trying to make it so that when my checkbox is checked, it freezes the value, rather than just setting it.

Code:
if (LOWORD(wParam) == POP_CHECK)
         {
            int POPState = SendMessage((HWND)lParam,BM_GETCHECK,0,0);
            if(POPState == BST_CHECKED)
            {               
               unsigned long popval = (unsigned long)(GetDlgItemInt(hwnd,WEIGHT_EDIT,NULL,FALSE));
               //copy popval into desired addy
               Sleep(50);
            }
            if(POPState == BST_UNCHECKED)
            {
            //copy original value
               Sleep(50);
            }
         }


But if I add a while loop:

Code:
if (LOWORD(wParam) == POP_CHECK)
         {
            int POPState = SendMessage((HWND)lParam,BM_GETCHECK,0,0);
            while(POPState == BST_CHECKED)
            {               
               unsigned long popval = (unsigned long)(GetDlgItemInt(hwnd,WEIGHT_EDIT,NULL,FALSE));
               //copy popval into desired addy
               Sleep(50);
            }
            while(POPState == BST_UNCHECKED)
            {
            //copy original value
               Sleep(50);
            }
         }


it will just stop responding as soon as I set one value. I can set values fine, but freezing them is another matter.
Back to top
View user's profile Send private message
oib111
I post too much
Reputation: 0

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Wed Jun 25, 2008 11:02 am    Post subject: Reply with quote

Try doing a do while loop. Something like this:

Code:

int POPState = SendMessage((HWND)lParam,BM_GETCHECK,0,0);
if(POPState == BST_CHECKED)
{
   do {
      unsigned long popval = (unsigned long)(GetDlgItemInt(hwnd,WEIGHT_EDIT,NULL,FALSE));
      //copy popval into desired addy
      Sleep(50);
      POPState = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
   } while(POPState == BST_CHECKED);
}


Also, may I suggest you use the handle to the checkbox rather than the lParam. It's much safter. And you don't need to typecast the lParam because lParam is the handle to the window that sent the message.

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jun 25, 2008 11:23 am    Post subject: Reply with quote

Create a new thread to loop.
_________________
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: Wed Jun 25, 2008 4:29 pm    Post subject: Reply with quote

Creating a loop there will stop the code from functioning because it will never exit the loop until you uncheck the box, so it will never get to handle other messages and such.

If you need it to loop, do what lurc said, create a thread so that it has the ability to loop that code, while still handling other messages.

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

Joined: 22 Feb 2008
Posts: 62

PostPosted: Wed Jun 25, 2008 7:41 pm    Post subject: Reply with quote

Wiccaan wrote:
Creating a loop there will stop the code from functioning because it will never exit the loop until you uncheck the box, so it will never get to handle other messages and such.

If you need it to loop, do what lurc said, create a thread so that it has the ability to loop that code, while still handling other messages.


Ok, but how would my new thread read the messages sent to my wndproc (wouldn't I have to check the messages first to loop, or would I handle the new thread like a function that I would just call)? Is there a specific winapi for this? (I've never done this before, bear with me please).
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
Goto page 1, 2  Next
Page 1 of 2

 
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