Lisp HUG Maillist Archive

Accessing the Windows message pump from LW/CAPI

And here's a second question, not directly related to my previous one:

The C library I'm interfacing to is meant to be used in such a way
that a Windows programming talking with it has to modify the Windows
message pump.  It has to call GetMessage, inspect the message to see
if it's for the library and hand it over, and only send all other
(i.e. normal) messages to the usual TranslateMessage, DispatchMessage
mechanism.

This is, I think, something than can't be done in CAPI.  What I came
up with is the following: I start a new ("worker") thread which
creates (using Win32 functions directly) a new hidden window and then
establishes its own message pump which it also uses to communicate
with the rest of the program.

Does this sound feasible or does anybody expect a problem there?  Am I
right to assume that if a new thread creates its own window that it
gets its own message queue from Windows which CAPI won't interfer with
because I'm not using CAPI in this thread?  Or is this approach
doomed?

Or is there a much better and elegant way to hook into the message
pump in CAPI?

Thanks,
Edi.


Re: Accessing the Windows message pump from LW/CAPI

Unable to parse email body. Email id is 10449

Re: Accessing the Windows message pump from LW/CAPI

Raymond, did you mean to register-module the Win32 library, or were
you talking about other, third-party C libs?

Thanks,
Edi.


On Wed, Aug 11, 2010 at 4:12 PM, Raymond C Laning <rclaning@raytheon.com> wrote:
> One note -
>
> I found that, for processes with their own non-CAPI window, their own
> message pump and a foreign library, I had to call register-module in that
> process to avoid problems w/CAPI's windows library.
>
>  Raymond Laning
>  Principal Systems Engr
>  Missile Systems
>  Raytheon Company
>
>
>
>
>  520.794.7924
>  rclaning@raytheon.com
>
>
>
>  1151 E Hermans Rd
>  Tucson, AZ 85756    www.raytheon.com
>
>
>  (Embedded image moved to file: pic03474.gif)Raytheon Sustainability
>
>  This message contains information that may be confidential and privileged.
>  Unless you are the addressee (or authorized to receive mail for the
>  addressee), you should not use, copy or disclose to anyone this message or
>  any information contained in this message. If you have received this message
>  in error, please so advise the sender by reply e-mail and delete this
>  message. Thank you for your cooperation.
>
>
>
>
>
>
>
>
>  From:       Martin Simmons <martin@lispworks.com>
>
>  To:         lisp-hug@lispworks.com
>
>  Date:       08/11/2010 05:19 AM
>
>  Subject:    Re: Accessing the Windows message pump from LW/CAPI
>
>  Sent by:    owner-lisp-hug@lispworks.com
>
>
>
>
>
>
>
>>>>>> On Wed, 11 Aug 2010 13:16:07 +0200, Edi Weitz said:
>>
>> And here's a second question, not directly related to my previous one:
>>
>> The C library I'm interfacing to is meant to be used in such a way
>> that a Windows programming talking with it has to modify the Windows
>> message pump.  It has to call GetMessage, inspect the message to see
>> if it's for the library and hand it over, and only send all other
>> (i.e. normal) messages to the usual TranslateMessage, DispatchMessage
>> mechanism.
>>
>> This is, I think, something than can't be done in CAPI.  What I came
>> up with is the following: I start a new ("worker") thread which
>> creates (using Win32 functions directly) a new hidden window and then
>> establishes its own message pump which it also uses to communicate
>> with the rest of the program.
>>
>> Does this sound feasible or does anybody expect a problem there?  Am I
>> right to assume that if a new thread creates its own window that it
>> gets its own message queue from Windows which CAPI won't interfer with
>> because I'm not using CAPI in this thread?  Or is this approach
>> doomed?
>>
>> Or is there a much better and elegant way to hook into the message
>> pump in CAPI?
>
> Your approach will work fine.  Window handles are owned by the thread that
> creates them and by default will use a per-thread message queue.
>
> --
> Martin Simmons
> LispWorks Ltd
> http://www.lispworks.com/
>
>


Re: Accessing the Windows message pump from LW/CAPI

Unable to parse email body. Email id is 10453

Re: Accessing the Windows message pump from LW/CAPI

On Wed, Aug 11, 2010 at 4:54 PM, Xu Jingtao <jingtaozf@gmail.com> wrote:

> I uses windows api |SetWindowLong| to hook message of capi pane.

That was very helpful and something I wasn't aware of before.  This
indeed looks more elegant to me than my own approach.

Thanks a lot, I'll try this.

Edi.


Re: Accessing the Windows message pump from LW/CAPI

On Wed, Aug 11, 2010 at 2:18 PM, Martin Simmons <martin@lispworks.com> wrote:

> Your approach will work fine.  Window handles are owned by the thread that
> creates them and by default will use a per-thread message queue.

This all works fine as long as the window is visible.  But if I create
the window with the win32:ws_visible flag not set, it doesn't work
anymore.  It seems to me as if messages are not sent to invisible
windows.  Is that true?  Maybe someone with more knowledge about
Windows can enlighten me?

Thanks,
Edi.


Re: Accessing the Windows message pump from LW/CAPI

>>>>> On Sun, 15 Aug 2010 23:16:29 +0200, Edi Weitz said:
> 
> On Wed, Aug 11, 2010 at 2:18 PM, Martin Simmons <martin@lispworks.com> wrote:
> 
> > Your approach will work fine.  Window handles are owned by the thread that
> > creates them and by default will use a per-thread message queue.
> 
> This all works fine as long as the window is visible.  But if I create
> the window with the win32:ws_visible flag not set, it doesn't work
> anymore.  It seems to me as if messages are not sent to invisible
> windows.  Is that true?  Maybe someone with more knowledge about
> Windows can enlighten me?

That is unexpected, in particular because DDE and COM/Automation both use
invisible windows to pass messages between application.

Have you tried using Spy++ to watch the messages?

Is the window enabled (it should be by default)?  

-- 
Martin Simmons
LispWorks Ltd
http://www.lispworks.com/


Re: Accessing the Windows message pump from LW/CAPI

On Mon, Aug 16, 2010 at 2:21 PM, Martin Simmons <martin@lispworks.com> wrote:

> That is unexpected, in particular because DDE and COM/Automation both use
> invisible windows to pass messages between application.

OK, that means it definitely should work which is an important piece
of information.

> Have you tried using Spy++ to watch the messages?

Heh, until now I didn't even know that I had it on my hard disk.  I'll
run some tests and report back.

> Is the window enabled (it should be by default)?

I didn't disabled it explicitly, but I'll double-check.

Thanks again for your help,
Edi.


Re: Accessing the Windows message pump from LW/CAPI

On Mon, Aug 16, 2010 at 3:13 PM, Edi Weitz <edi@agharta.de> wrote:

>> Have you tried using Spy++ to watch the messages?
>
> Heh, until now I didn't even know that I had it on my hard disk.  I'll
> run some tests and report back.

Which I'm doing now for the sake of completeness: The funny thing was
that the invisible window didn't receive messages but started to
receive them once I monitored it with Spy++.  Which - after some
head-scratching - helped me figure out that I had a race condition in
my code.  In other words: Spy++ slowed down the whole process just
enough to make the race condition disappear.

Looks like this is solved and I'm off to the next problem.

Thanks,
Edi.


Updated at: 2020-12-10 08:39 UTC