Re: String --> Pointer --> LongInt



On Thu, 13 Oct 2005 21:05:31 +0100, "Hary" <haryhary@xxxxxxxx> wrote:

>the code below worx fine:
>
>
>Global Var A: String;
>
>begin
> PostMessage(self.Handle,Msg1,0,LongInt(Pointer(A)));
>end;

So you are going in for obfuscation and using PostMessage
- as far as I remember I'm the person who suggested that in another
thread

As you've already been warned, this is rather dangerous for sending
strings as they can move around.

Here is what it says in the Win32 Programmer's Reference

<quote>
If you send a message in the range below WM_USER to the asynchronous
message functions (
PostMessage, SendNotifyMessage, and SendMessageCallback), make sure
that the message parameters do not include pointers. Otherwise, the
functions will return before the receiving thread has had a chance to
process the message and the sender will free the memory before it is
used.
</quote>

I must confess I am not sure what WM_USER has to do with it, it is
profoundly unlikely that PostMessage changes its behaviour from
asynchronous to synchornous above WM_USER

One technique I used successfully for inter app communication was to
break the string into four byte chunks and send a stream of messages,
with the string being 'rebuilt' by the recipient.

It sounds rather wasteful, but generates a lot less activity than
simply waving the mouse.
.



Relevant Pages

  • Re: String between unmanaged and managed
    ... Directly from Help on PostMessage: ... exit before the receiver copies off the data (it's quite likely to happen in ... PostMessage(hwndinoc, 20000, (WPARAM) textitem, textlen); ... I have tried, the problem is that I always receive an invalid string, ...
    (microsoft.public.windowsce.app.development)
  • Re: Postmessage API
    ... Also review the PostMessage declaration. ... declare function PostMessage lib "user32.dll" (byval hWnd as intptr, ... | Private Sub Button1_Click(ByVal sender As System.Object, ... | "FindWindowA" (ByVal lpClassName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Combobox: WM_SETTEXT doesnt work while Sendkeys works ???
    ... PostMessage hits the other App - or even the same App ... that any String sent ByVal or ByRef will be copied and zapped as soon ...
    (microsoft.public.vb.winapi)
  • Re: Closing modeless dialogs
    ... CString * s = new CString; ... Maybe you could add the string object as a CString to your ... With PostMessage I could not send strings (I ... MVP Tips: http://www.flounder.com/mvp_tips.htm ...
    (microsoft.public.vc.mfc)
  • Re: Closing modeless dialogs
    ... the real syntactic extension is the 'with' clause... ... CString * s = new CString; ... Maybe you could add the string object as a CString to your ... With PostMessage I could not send strings (I ...
    (microsoft.public.vc.mfc)