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 


Error with PostMessageX
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
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 7:44 pm    Post subject: Error with PostMessageX Reply with quote

I'm gonna make a personal AC (i dont need full bot) using pmx.dll
I can load it and GetProcAddress but when i call i get a error violation

Code:
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#define ID_TIMER 2

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
typedef bool (__cdecl *MYPROC)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

static char sClassName[] = "MyClass";
static HINSTANCE zhInstance = NULL;
HMODULE hDll;
MYPROC hhPostMessageA;
bool tbool = FALSE;

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
    int nCmdShow) {
            WNDCLASSEX WndClass;
      HWND hwnd;
       MSG Msg;


       zhInstance = hInstance;

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

       if(!RegisterClassEx(&WndClass)) {
               MessageBox(0, "Error Registering Class!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }

       hwnd = CreateWindowEx(WS_EX_STATICEDGE, sClassName, "Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,

CW_USEDEFAULT,
                      100, 175, NULL, NULL, zhInstance, NULL);

       if(hwnd == NULL) {
               MessageBox(0, "Error Creating Window!", "Error!", MB_ICONSTOP | MB_OK);
               return 0;
       }
       ShowWindow(hwnd, nCmdShow);
       UpdateWindow(hwnd);

            while(GetMessage(&Msg, NULL, 0, 0)) {
               TranslateMessage(&Msg);
               DispatchMessage(&Msg);
       }

       return Msg.wParam;
}



LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
       switch(Message) {
         case WM_CREATE:
         if(!RegisterHotKey(hwnd, 1, MOD_CONTROL, VK_F11))
            MessageBox(hwnd, "Hotkey F11 failed!", "Error", MB_OK);
         if(!RegisterHotKey(hwnd, 2, MOD_CONTROL, VK_F12))
            MessageBox(hwnd, "Hotkey F12 failed!", "Error", MB_OK);


         hDll = LoadLibrary("hookHop.dll");
         if(hDll == 0)
            MessageBox(hwnd, "PMX.dll failed to load", "Error", MB_OK);


         hhPostMessageA = (MYPROC)GetProcAddress(hDll, "hhPostMessageA");
         if ( hhPostMessageA != NULL)
         {
            tbool = TRUE;
         }

         if(!FreeLibrary(hDll))
            MessageBox(hwnd, "Error in FreeLibrary", "Error", MB_OK);

         break;
   
         case WM_HOTKEY:
         if(wParam == 1)
            SetTimer(hwnd, ID_TIMER, 2000, NULL);

         if(wParam == 2)
            KillTimer(hwnd, ID_TIMER);

         break;

         case WM_TIMER:
         if(wParam == ID_TIMER)
         {
            if(tbool == TRUE)
            {
            (hhPostMessageA)(NULL, WM_KEYDOWN, 41,0x00);
            }
         }
         break;
            case WM_CLOSE:
                       DestroyWindow(hwnd);
            break;

            case WM_DESTROY:
                  KillTimer(hwnd, ID_TIMER);
                       PostQuitMessage(0);
            break;

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




The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________


Last edited by HomerSexual on Thu Dec 06, 2007 8:20 pm; edited 2 times in total
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 7:49 pm    Post subject: Reply with quote

Use hookHop. PMX is a bloated piece of shit. Not sure what C++ needs to import w/out LoadLibrary... but I have included a lib just in case.
_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:02 pm    Post subject: Reply with quote

Edited code to reflect hookHop and hhPostMessageA

The program crashes...

_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:04 pm    Post subject: Reply with quote

provide a binary... and shouldn't there be another way to link it... not load dll on runtime.. nvm about the typedef thing. i thought myproc = hhpostmessageA... but you call it as (hhpostmessageA) ...

not really sure... i dont know c well.

_________________


Last edited by sponge on Thu Dec 06, 2007 8:07 pm; edited 1 time in total
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:07 pm    Post subject: Reply with quote

Code:
typedef bool (__cdecl *MYPROC)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);

 hDll = LoadLibrary("hookHop.dll");
         if(hDll == 0)
            MessageBox(hwnd, "PMX.dll failed to load", "Error", MB_OK);


         hhPostMessageA = (MYPROC)GetProcAddress(hDll, "hhPostMessageA");
         if ( hhPostMessageA != NULL)
         {
            tbool = TRUE;
         }

         if(!FreeLibrary(hDll))
            MessageBox(hwnd, "Error in FreeLibrary", "Error", MB_OK);


That defines MYPROC as hWnd, Msg, wParam, lParam then defines hhPostMessageA as type MYPROC and then i call (hhPostMessageA)

_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:08 pm    Post subject: Reply with quote

Provide a binary? or just try stepping the code yourself... i dont have a compiler installed.
I am in no terms a C expert but just some quick googling... could you not do this?
Quote:

C and C++

Make sure you include Example.lib file(assuming that Example.dll is generated) in the project (Add Existing Item option for Project!)before static linking. The file Example.lib is automatically generated by the compiler when compiling the DLL. Not executing the above statement would cause linking error as the linker would not know where to find the definition of AddNumbers. You also need to copy the DLL Example.dll to the location where the .exe file would be generated by the following code.

Code:
#include <windows.h>
#include <stdio.h>

// Import function that adds two numbers
extern "C" __declspec(dllimport) double AddNumbers(double a, double b);

int main(int argc, char **argv)
{
        double result = AddNumbers(1, 2);
        printf("The result was: %f\n", result);
        return 0;

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:17 pm    Post subject: Reply with quote

Unhandled exception at 0x1000103a in AutoClickMaple.exe: 0xC0000005: Access violation.
Picture attached of call stack frame error



help.jpg
 Description:
 Filesize:  18.78 KB
 Viewed:  8983 Time(s)

help.jpg



_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:20 pm    Post subject: Reply with quote

What you're giving me isn't going to help...
http://msdn2.microsoft.com/en-us/library/ms686923.aspx
i stillt hink this is a great way to load dlls that need to be constantly used.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:25 pm    Post subject: Reply with quote

Sponge, It's a Memory Error

You're functions are reading executable memory not readable. It's not vista compat?

_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:27 pm    Post subject: Reply with quote

It should be... the stack isn't a memory read violation. as far as i'm concerned... API header for vista is still the same. hookHop only reads within its own module.
once again a binary wouuld be most helpful in order to debug. because of the fact that my C knowledge is limited.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:30 pm    Post subject: Reply with quote

uploaded exe on top about 15 minutes ago?
_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:32 pm    Post subject: Reply with quote

blankrider wrote:
uploaded exe on top about 15 minutes ago?

wow... i didnt even show up until i saw this post and even then i had to refresh like 20 times i cant open it in olly... is your compiler making it only for vista... or does debug info screw stuff up...

This isn't even a crash... the windows loader won't load it.

_________________
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Thu Dec 06, 2007 8:43 pm    Post subject: Reply with quote

There are 2 errors

in FreeLibrary and my calling of hhPostMessageA in WM_TIMER

_________________
Back to top
View user's profile Send private message
sponge
I'm a spammer
Reputation: 1

Joined: 07 Nov 2006
Posts: 6009

PostPosted: Thu Dec 06, 2007 8:48 pm    Post subject: Reply with quote

I really don't know what the problem is... first off mine won't even run... and i've tested my dll and it works perfectly. others have used it too.
_________________
Back to top
View user's profile Send private message
fl00d
Newbie cheater
Reputation: 0

Joined: 21 Nov 2007
Posts: 14

PostPosted: Thu Dec 06, 2007 11:49 pm    Post subject: Reply with quote

I'm getting the same error...I'm also using function pointers to the hhPostMessageA. I'm gonna try to import the exports @ runtime 'cause usually these errors are because of incorrect pointer handling. I'll let you know...
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