unmanaged events

  • Thread starter Thread starter leibnizster
  • Start date Start date
L

leibnizster

Hello.

How can I catch events from an unmanaged dll written in C++? I do not
have access to the source code of the unmanaged .dll. I have a
documentation and the names of the events and functions. So, any ideas?

Thanks
 
I have never worked with unmanaged events before and I don't want to
install unnecessary dlls if I can do it myself (opennetcf). So, can you
please tell me or give me a link about how I can declare the unmanaged
events in my code? i found this on a thread:


1. In your C# app, create a delegate and an event.
2. In your C# app create a thread that calls CreateEvent with the
event
name from your C++ app then calls WaitForSingleObject on that handle.
I'd
put a 200ms timeout and loop as long as it's a TIMEOUT.
3. After the WaitForSingleObject call loop, raise the event from step
#1

4. In your C++ app create a named event
5. When you want to signal, raise that event, which get caught by #2
above
and signaled as an event in #3

--
Chris Tacke, eMVP


Is it enough to call CreateEvent with a parameter that corresponds with
the unmanaged event? Can the runtime match the two?
 
The steps I outlined before and you found haven't changed. At a bare
minimum you have to P/Invoke CreateEvent (step 2) and P/Invoke
WaitForSingleObject on the returned handle. Of course to be of any use
it'll have to be in a worker thread, so raining a managed event only makes
sense (#1 and #3). #4 and #5 are what the 3rd party DLL you're using does.
The SDF code is shared. Open it up and look how it's done.

-Chris
 
Sorry for appearing stupid but,

the question I have is about the CreateEvent function:

HANDLE CreateEvent(
LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset,
BOOL bInitialState,
LPTSTR lpName
);

How must I pass the lpName parameter? How does the runtime know that
it's from the .dll I want? Shouldn't I declare it somewhere first? I
know that events can't be marshaled, but I can't really understand how
this works.

Anyway, thanks for all your answers.
 
You simply use the same string name from both event consumers. So your app
must use the exact same string when it calls CreateEvent that the 3rd party
library that's setting the event used. If that's not documented by the 3rd
party provider, then there's no way to catch the events.

-Chris
 
Back
Top