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++]PostMessage function..

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

Joined: 16 Jun 2006
Posts: 551

PostPosted: Thu Aug 28, 2008 11:30 pm    Post subject: [C++]PostMessage function.. Reply with quote

Trying to get familiar with win32 api / postmessage function. I simply wish to send a message to notepad.



Code:
#include <windows.h>
using namespace std;

void main()
{
   
HWND hWnd = FindWindow( NULL, "Untitled - Notepad" );
HWND hWndChild = FindWindowEx( hWnd, NULL, "Edit", NULL );
PostMessage( hWndChild, WM_KEYDOWN, 0x5A, 0x5A );
}



Major Error:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\Matt\Desktop\TestPM\Debug\TestPM.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Matt\Desktop\TestPM\TestPM\Debug\BuildLog.htm"
TestPM - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Not sure whats wrong here.

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

Joined: 24 Dec 2007
Posts: 1268

PostPosted: Thu Aug 28, 2008 11:53 pm    Post subject: Reply with quote

int main();

return 0;

I think.
Back to top
View user's profile Send private message Send e-mail
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Thu Aug 28, 2008 11:59 pm    Post subject: Reply with quote

Quote:
MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup
C:\Documents and Settings\Matt\Desktop\TestPM\Debug\TestPM.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\Documents and Settings\Matt\Desktop\TestPM\TestPM\Debug\BuildLog.htm"
TestPM - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Tried and got that.down to 1 error..

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

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Aug 29, 2008 12:18 am    Post subject: Reply with quote

Are you doing something funky to try and avoid the CRT?

Otherwise, check your subsystem setting in the linker settings and make sure it's set appropriately.

If you're still having trouble for some reason, the linker is expecting mainCRTStartup, so create your own function and you will be fine.


Last edited by hcavolsdsadgadsg on Fri Aug 29, 2008 3:27 am; edited 1 time in total
Back to top
View user's profile Send private message
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5094
Location: Israel.

PostPosted: Fri Aug 29, 2008 3:21 am    Post subject: Reply with quote

Change "main" to "WinMain" or change the entry point at settings -> Linker -> Advanced.
Back to top
View user's profile Send private message
Renkokuken
GO Moderator
Reputation: 4

Joined: 22 Oct 2006
Posts: 3249

PostPosted: Fri Aug 29, 2008 4:14 am    Post subject: Reply with quote

Your linker options are set to SUBSYSTEM:WINDOWS, while you're trying the entry point of a CONSOLE application. Either change the subsystem, or make it a WinMain entry point.
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Fri Aug 29, 2008 1:50 pm    Post subject: Reply with quote

Code:
#include <windows.h>
#include <iostream>
using namespace std;

int sendmsgplz()
{
   
HWND hWnd = FindWindow( NULL, "Untitled - Notepad" );
HWND hWndChild = FindWindowEx( hWnd, NULL, "Edit", NULL );
PostMessage( hWndChild, WM_KEYDOWN, 0x5A, 0x5A );
return 0;
}


Still same external linker error.... :[

_________________
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 29, 2008 1:58 pm    Post subject: Reply with quote

You created the project as a windows application, meaning the main entry point has to be WinMain as Symbol and Renko have mentioned.
Also the lParam of WM_KEYDOWN is the scan-code, repeat-count, etc. You can just leave it at 0. Also if your just gonna send a char to the edit then use WM_CHAR instead.

Heres how it should look:
Code:
#include <windows.h>
#include <tchar.h>

BOOL APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )
{
    UNREFERENCED_PARAMETER( hInstance );
    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nShowCmd );

    HWND hWnd = FindWindow( _T("Notepad"), NULL );   // Use the class instead.
    if ( hWnd != NULL )
    {
        HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL );
        if ( hChild != NULL )
            PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 );
    }
    return 0;
}

_________________
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Aug 30, 2008 9:49 am    Post subject: Reply with quote

lurc wrote:
You created the project as a windows application, meaning the main entry point has to be WinMain as Symbol and Renko have mentioned.
Also the lParam of WM_KEYDOWN is the scan-code, repeat-count, etc. You can just leave it at 0. Also if your just gonna send a char to the edit then use WM_CHAR instead.

Heres how it should look:
Code:
#include <windows.h>
#include <tchar.h>

BOOL APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )
{
    UNREFERENCED_PARAMETER( hInstance );
    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nShowCmd );

    HWND hWnd = FindWindow( _T("Notepad"), NULL );   // Use the class instead.
    if ( hWnd != NULL )
    {
        HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL );
        if ( hChild != NULL )
            PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 );
    }
    return 0;
}



Error - "WC_EDIT" is an undeclared identifier.

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

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Sat Aug 30, 2008 9:52 am    Post subject: Reply with quote

manc wrote:
lurc wrote:
You created the project as a windows application, meaning the main entry point has to be WinMain as Symbol and Renko have mentioned.
Also the lParam of WM_KEYDOWN is the scan-code, repeat-count, etc. You can just leave it at 0. Also if your just gonna send a char to the edit then use WM_CHAR instead.

Heres how it should look:
Code:
#include <windows.h>
#include <tchar.h>

BOOL APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )
{
    UNREFERENCED_PARAMETER( hInstance );
    UNREFERENCED_PARAMETER( hPrevInstance );
    UNREFERENCED_PARAMETER( lpCmdLine );
    UNREFERENCED_PARAMETER( nShowCmd );

    HWND hWnd = FindWindow( _T("Notepad"), NULL );   // Use the class instead.
    if ( hWnd != NULL )
    {
        HWND hChild = FindWindowEx( hWnd, NULL, WC_EDIT, NULL );
        if ( hChild != NULL )
            PostMessage( hChild, WM_CHAR, (WPARAM)'Z', 0 );
    }
    return 0;
}



Error - "WC_EDIT" is an undeclared identifier.


Then look up what it should be instead of wanting him to hand you full code

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

Joined: 13 Mar 2007
Posts: 542

PostPosted: Sat Aug 30, 2008 2:37 pm    Post subject: Reply with quote

Lol, this is why i stick to delphi.
Back to top
View user's profile Send private message
DeletedUser14087
I post too much
Reputation: 2

Joined: 21 Jun 2006
Posts: 3069

PostPosted: Sat Aug 30, 2008 3:14 pm    Post subject: Reply with quote

NULL lparam, read more about notifications @ MSDN
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Sat Aug 30, 2008 3:44 pm    Post subject: Reply with quote

Oh yea, forgot to #include <commctrl.h> for WC_EDIT...
_________________
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