Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FindWindow and PostMessage compile problems

Status
Not open for further replies.

poicito

Programmer
Feb 6, 2004
4
US
I am a total newbie at VC++ (I am a pathetic, lowly VB programmer). I am creating a program in VC++ to send some information via PostMessage to a program called MacroExpress (to tell it to run a specific macro, etc). When compiling, I get the postmessagea "function does not take 4 parameters" although postmessage does take 4.

Here's what I've got. If anyone could show me how this code would look when corrected, I would much appreciate it. Like I said, I'm a total newby, so explaining won't help as much as posting the same code in working order :)

There's probably a number of problems with it.

void CAboutDlg::OnButton1()
{

LPCTSTR S;
S = "TESTMACRO";
CWnd *pWnd = FindWindow( NULL , "Macro Express Player" );
HWND hWnd = pWnd->GetSafeHwnd();
int tt;
tt = WM_USER + 20;

int slen;
slen = strlen(S);

for (int x=0;x<slen;x++)
PostMessage(hWnd,tt,S[x],0);
PostMessage(hWnd,tt,0,0);
return;
}


That code causes compile errors for both postmessage lines:

error C2660: 'PostMessageA' : function does not take 4 parameters
error C2660: 'PostMessageA' : function does not take 4 parameters

Anyone who helps out will be much appreciated.
 
As you wrote the code you are calling CWnd::postMessage() which expects only 3 parameters.
To work your code :
::postMessage(hWnd,tt,S[x],0);
-obislavu-

 
THANKS!!! That worked. The working code looks like this:

void CAboutDlg::OnButton1()
{

LPCTSTR S;
S = &quot;TESTMACRO&quot;;
CWnd *pWnd = FindWindow( NULL , &quot;Macro Express Player&quot; );
HWND hWnd = pWnd->GetSafeHwnd();
int tt;
tt = WM_USER + 20;

int slen;
slen = strlen(S);

for (int x=0;x<slen;x++)
::postMessage(hWnd,tt,S[x],0);
::postMessage(hWnd,tt,0,0);
return;
}
 
One more question. I put that same code into a DLL and it gives me a error C2440: 'initializing' : cannot convert from 'struct HWND__ *' to 'class CWnd *' error

Here's what I'm putting in:

int _stdcall MacexGo(LPCTSTR S)
{

CWnd *pWnd = FindWindow( NULL , &quot;Macro Express Player&quot; );
HWND hWnd = pWnd->GetSafeHwnd();

int tt;
tt = WM_USER + 20;

int slen;
slen = strlen(S);

for (int i=0;i<slen;i++)
::postMessage(hWnd,tt,S,0);
::postMessage(hWnd,tt,0,0);
return 0;

}


and I get the following error about the findwindow line:

error C2440: 'initializing' : cannot convert from 'struct HWND__ *' to 'class CWnd *'

It's weird that it would work in the EXE but not in a DLL. Any ideas?

Again, code example would help me more than explaination, as I am a total newbie.
 
Sorry about the first postmessage line and the italics. In my code the S is followed by a [ i ], but on this site, that creates italics.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top