Xojo Conferences
MBSOct2019CologneDE

Callbacks and events on Windows (Real Studio Plugins Mailinglist archive)

Back to the thread list
Previous thread: newbie question - how to store a file from the disk in the database
Next thread: Question(s) about Failed Assertion


macosx and unix paths   -   GOLD
  Callbacks and events on Windows   -   Dave Addey
   Re: Callbacks and events on Windows   -   James Milne
    Re: Callbacks and events on Windows   -   Dave Addey
     Storing global data (was Callbacks and events on Windows)   -   Dave Addey

Callbacks and events on Windows
Date: 26.04.06 12:42 (Wed, 26 Apr 2006 12:42:54 +0100)
From: Dave Addey
Hi all,

I¹m making good progress with some HID classes for MachO / Win32. I¹ve got
a ³data available² event callback working fine on MachO, following James
Milne¹s approach of creating factories to manage the creation of custom
objects. This works by calling an object instance¹s DataAvailable event
whenever data is available for that object. A reference to the object
instance is passed to the callback function installer, and this reference is
used (when the callback is called) to get a function pointer for the event
and call back into the RB code.

I¹m now trying to do the same thing on Win32. My knowledge of Win32 coding
isn¹t great, but I think I have the following options:

1. Create a new (Win32) thread via CreateThread, with an event loop which
checks for custom events I have defined
2. Hook in to a window event loop via the approach mentioned by Aaron here:
http://www.aaronballman.com/programming/REALbasic/WindowSubclassingArticle.p
hp to check for my custom events in the window

1) should work, I think, but I¹m pretty sure that calling back into RB code
from this background thread will cause problems due to RB not being
thread-safe. 2) would work also, I think, but ties the events to being
processed by a window, and really I want to call into the custom class
instance¹s event, not a custom window event.

Is there any other way to do this on Win32? That is, to either define a
callback which isn¹t tied to a window, or to use a thread to check for the
events in the background whilst still safely calling into RB code from the
thread?

Any help very much appreciated on this one!

All the best,

Dave.
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Callbacks and events on Windows
Date: 26.04.06 12:56 (Wed, 26 Apr 2006 12:56:11 +0100)
From: James Milne
Dave Addey wrote:
> Hi all,
>
> I¹m making good progress with some HID classes for MachO / Win32. I¹ve got
> a ³data available² event callback working fine on MachO, following James
> Milne¹s approach of creating factories to manage the creation of custom
> objects. This works by calling an object instance¹s DataAvailable event
> whenever data is available for that object. A reference to the object
> instance is passed to the callback function installer, and this reference is
> used (when the callback is called) to get a function pointer for the event
> and call back into the RB code.
>
> I¹m now trying to do the same thing on Win32. My knowledge of Win32 coding
> isn¹t great, but I think I have the following options:
>
> 1. Create a new (Win32) thread via CreateThread, with an event loop which
> checks for custom events I have defined
> 2. Hook in to a window event loop via the approach mentioned by Aaron here:
> http://www.aaronballman.com/programming/REALbasic/WindowSubclassingArticle.p
> hp to check for my custom events in the window
>
> 1) should work, I think, but I¹m pretty sure that calling back into RB code
> from this background thread will cause problems due to RB not being
> thread-safe. 2) would work also, I think, but ties the events to being
> processed by a window, and really I want to call into the custom class
> instance¹s event, not a custom window event.
>
> Is there any other way to do this on Win32? That is, to either define a
> callback which isn¹t tied to a window, or to use a thread to check for the
> events in the background whilst still safely calling into RB code from the
> thread?
>
> Any help very much appreciated on this one!

Approach #1 is not gonna fly- you can't call into REALbasic code from that other thread. Bad Things Will Happen.

Approach #2 is probably heading in the right direction.

I must admit I've never attempted to do any HID work on Windows, so I don't know how it passes events to the application. What API are you using?

You could create your own hidden offscreen window using the Win32 APIs and catch the HID events using your own WndProc.

--
Kind reg

Re: Callbacks and events on Windows
Date: 26.04.06 13:10 (Wed, 26 Apr 2006 13:10:14 +0100)
From: Dave Addey
> Approach #1 is not gonna fly- you can't call into REALbasic code from that
> other thread. Bad Things Will Happen.
>
> Approach #2 is probably heading in the right direction.
>
> I must admit I've never attempted to do any HID work on Windows, so I don't
> know how it passes events to the application. What API are you using?
>
> You could create your own hidden offscreen window using the Win32 APIs and
> catch the HID events using your own WndProc.

Hi James,

Thanks for the advice!

I wondered if that might be the case for Approach 1. Bah. Thanks for the
confirmation. I've used background threads in plugins before, but only
where there's no interaction with RB, so I wondered if this might be the
case.

I'm using DirectInput for the HID support on Windows. It seems to *nearly*
do everything I need, with the possible exception of support for device
elements with big data values (i.e. "more than a DWORD"), which is
unfortunately the case for a lot of interesting devices. I think this
should be possible to implement, however, as soon as my Windows Driver
Development Kit CD turns up. I've got device and device element discovery,
information gathering, and event polling all working nicely on Win32 and
MachO. But the killer feature is to be able to be notified when events
arrive on Win32 too.

So approach 2 it is, then. I'm very intrigued by your suggestion of
creating a hidden offscreen window. Would this window need to be frontmost
window to receive events? I've not really got my head round Windows'
reliance on windows (if you see what I mean) in order to receive events in a
GUI application. Are the concepts of 'my application is active' and 'one of
my windows is frontmost' one and the same thing in Win32?

I know I can set the cooperative level for a device:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/
IDirectInputDevice8__SetCooperativeLevel.asp

...and the most useful scenario is when the application is frontmost. But
what if the app has many windows? How does this affect my use of a window
as the event handler?

The hidden offscreen window approach is definitely worth exploring. Any
pointers as to how one would go about doing this? Sorry to ask - but this
particular part of it is all new to me...

Thanks again for the help,

Dave.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>