Re: PostMessage() Error
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eF2VU2pVHHA.1200@TK2MSFTNGP04.phx.gbl...
one2001boy@yahoo.com wrote:
is there a way to send a string using PostMessage()?
int status;
unsigned char c, s[90] = "message to be sent";
c = s[0];
// the following works
status = PostMessage(hwnd, WM_CHAR, c, 1L);
// the following doesn't work
status = PostMessage(hwnd, WM_CHAR, s, strlen(s));
You can put anything you want into parameters accompanying WM_CHAR
message. PostMessage will dutifully deliver them to the window procedure
of the target window. However, said window proc will interpret these
values according to the documentation - character code in wParam, flags in
lParam. The second call you show basically sends garbage.
Also note that for windows in any other process, even if the item is
interpreted as a pointer, your pointer is meaningless in any other
application. Windows treats a few messages specially (generally those
requiring strings with value < WM_USER) to make a copy of the string in the
other application and change the pointer to use that copy, but you still
should be aware of the problem.
You can of course send a series of WM_CHAR messages, each carrying a
single character.
What are you trying to achieve? State your problem, not a proposed
solution that doesn't work. Chances are, there are better ways to proceed.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925