| View previous topic :: View next topic |
| Author |
Message |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu Aug 28, 2008 11:30 pm Post subject: [C++]PostMessage function.. |
|
|
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 |
|
 |
kitterz Grandmaster Cheater Supreme
Reputation: 0
Joined: 24 Dec 2007 Posts: 1268
|
Posted: Thu Aug 28, 2008 11:53 pm Post subject: |
|
|
int main();
return 0;
I think.
|
|
| Back to top |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Thu Aug 28, 2008 11:59 pm Post subject: |
|
|
| 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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Aug 29, 2008 12:18 am Post subject: |
|
|
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 |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Fri Aug 29, 2008 3:21 am Post subject: |
|
|
| Change "main" to "WinMain" or change the entry point at settings -> Linker -> Advanced.
|
|
| Back to top |
|
 |
Renkokuken GO Moderator
Reputation: 4
Joined: 22 Oct 2006 Posts: 3249
|
Posted: Fri Aug 29, 2008 4:14 am Post subject: |
|
|
| 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 |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Fri Aug 29, 2008 1:50 pm Post subject: |
|
|
| 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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Aug 29, 2008 1:58 pm Post subject: |
|
|
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 |
|
 |
manc Grandmaster Cheater
Reputation: 1
Joined: 16 Jun 2006 Posts: 551
|
Posted: Sat Aug 30, 2008 9:49 am Post subject: |
|
|
| 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 |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Aug 30, 2008 9:52 am Post subject: |
|
|
| 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 |
|
 |
kb3z0n Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 542
|
Posted: Sat Aug 30, 2008 2:37 pm Post subject: |
|
|
| Lol, this is why i stick to delphi.
|
|
| Back to top |
|
 |
DeletedUser14087 I post too much
Reputation: 2
Joined: 21 Jun 2006 Posts: 3069
|
Posted: Sat Aug 30, 2008 3:14 pm Post subject: |
|
|
| NULL lparam, read more about notifications @ MSDN
|
|
| Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Sat Aug 30, 2008 3:44 pm Post subject: |
|
|
Oh yea, forgot to #include <commctrl.h> for WC_EDIT...
_________________
|
|
| Back to top |
|
 |
|