listen to WM_USER -type messages sent from evC++ DLL -- possible?

D

dvanderboom

In CF, how do I listen to WM_USER -type messages sent from an evC++
app? Can I use OpenNETCF's ApplicationEx.AddMessageFilter and listen to
messages sent from an external application? The only options I'm given
in the C++ library are using a callback, which CF doesn't support via
interop (right?), or sending an Hwnd handle. Can I do this using the
Microsoft.WindowsCe.Forms.MessageWindow class (to get an Hwnd), and
somehow hook into it using OpenNETCF? How would this work? Does anyone
know or have sample code to perform this trick?
Any help will be greatly appreciated!
 
C

Chris Tacke, eMVP

I think either an IMessageFilter or MessageWindow would work depending on
how the sender is targeting the message (broadcast to all windows or to a
specific one). What are you trying to achieve exactly?

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 
P

Peter Foot [MVP]

The MessageWindow will give you a hidden window with it's own Hwnd which you
can pass to the native method. You then handle incoming messages as you
would in a WndProc in a C++ application. There is an article here:-
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/messagewindow.asp

The IMessageFilter will allow you to capture incoming messages sent to your
main form. Your PreFilterMessage method will get called and you can process
messages as required, there is an example here:-
http://wiki.opennetcf.org/ow.asp?Articles/AppIdleTimer

Peter
 
D

dvanderboom

I'm trying to call the following native method:

DWORD WINAPI RFID_EnableTriggerMessage(HANDLE *phTrigger, HANDLE
hReader,
BOOL bFlag, HWND hDlg, unsigned int
nTriggerMessage,
DWORD dwTriggerMask);

I have to send an HWND parameter to indicate where the message should
be sent. Here's my extern definition:

[DllImport("RFIDAPI32.dll", EntryPoint="#102")]
public static extern uint RFID_EnableTriggerMessage(
ref IntPtr phTrigger,
IntPtr hReader,
bool bFlag,
IntPtr hDlg,
uint nTriggerMessage,
uint dwTriggerMask);

So for the hDlg parameter, I pass it MyMessageWindow.Hwnd. Before I
call this method, the triggering action does nothing. However, after
the call, the triggering action actually closes my whole application.
I set a breakpoint in my WndProc function but it never stops there.
Native applications calling this function work fine.
 
P

Peter Foot [MVP]

Make sure the Hwnd for the messagewindow is valid (Not IntPtr.Zero) before
you pass it to the method, it is not created immediately when the
constructor for your MessageWindow derived class is executed.

Peter
 
D

dvanderboom

Yep, I checked. I got a value 4668880 for the hDlg handle last time I
ran it. I'm stepping through the code, so that should give it plenty
of time. All my parameters have expected values going into the call.
Still it closes my app. I'm confused.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top