Re: How to implement callback?
- From: "Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT com>
- Date: Tue, 30 Jan 2007 09:14:38 -0700
You need to build some means of communication between processes so that the
call occurs from inside the target process. Just as an example, you might
imagine that there's an event that indicates that all process callbacks
should be made. You might have a DLL which implements a RegisterCallback()
method which the application calls to register its interest in the callback
and pass the pointer to a callback function. RegisterCallback() might look
like this:
void RegisterCallback( fnPointer p, LONG param )
{
// Store the parameter in a table of callbacks, along with the function
pointer.
table[ items ].p = p;
table[ items ].param = param;
items++;
// Check whether the event notification thread is already running. If
not, start it.
if ( !hThread )
{
hThread = CreateThread( ...threadProc... );
CloseHandle( hThread );
}
}
LONG threadProc( ... )
{
// Create a handle to the system-wide event that indicates that I should
call-back
// my clients.
hEvent = CreateEvent(...);
while ( continueRunningFlag )
{
if ( WaitForSingleObject( hEvent, INFINITE ) == WAIT_OBJECT_0 )
{
// Iterate over the list of callbacks, calling each one.
for ( int i = 0; i < items; i++ )
{
(*table[ i ].p)( table[ i ].param );
}
}
else
{
break; // Error.
}
}
CloseHandle( hEvent );
}
Obviously, you'll have to handle synchronizing access to the table,
controlling when the thread exits, removing callbacks from the table, and,
in your other process, setting the event at a suitable time, but you should
get the idea. This is a *very* rough bit of code, so don't even think about
trying to use it as-is. You may also have to handle sending parameters from
the other application. If that's the case, you'd be better off using
something like a point-to-point message queue to receive the notifications
that it's time to call the callbacks, since some data can be sent via the
queue, also.
I think that's about as far as we can help without knowing why you've built
things this way...
Paul T.
"mygogo" <mygogo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E408C878-53CA-4F47-AAF8-9766B04E503E@xxxxxxxxxxxxxxxx
Thank you, Paul.
I did not use "managed" language. I used native C language.
I wanted to know how to call the callback functions registered to my
certerial hook manager. I had got the callback function's pointer, but it
was
in another process, I don't know how to call it in a right way.
"Paul G. Tobey [eMVP]" wrote:
"Managed" in the sense of written in C# or VB.NET? You should be able to
do
this with a delegate in .NET CF 2.0. You can't do it at all in .NET CF
1.0
and you'll have to find another way, if that's your target framework.
You'd
get the pointer to the delegate and call your centralized hook manager,
passing that pointer, just as you'd do with the function pointer passed
to
SetWindowsHookEx() in unmanaged code...
Paul T.
"mygogo" <mygogo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:80EEEB30-344C-45B0-BAD8-461C98BA7E88@xxxxxxxxxxxxxxxx
Thank you for your reply, Barry.
I wrapped the SetWindowsHookExW on my device, and I managed several
hooks
by
myself.
What I did was registering my program as the only hook on the system,
and
others hooking programs were managed by my program. I want to know how
to
perform a callback to the managed hooking program.
My English is not well, can you understand me?
"Barry Bond [MS]" wrote:
On the desktop, you call the CallNextHookEx() API to invoke the next
hook
in
the chain. I don't have my CE 5.0 docs handy... does this API show up
in
your SDK?
Barry
"mygogo" <mygogo@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:00BB2545-45B5-432E-828D-DA6702A75C55@xxxxxxxxxxxxxxxx
Hello,
I am writing code to hook function SetWindowsHookExW on Windows CE
5.
My code can hook the function correctly. But there is a problem, I
don't
know how to invoke the user defined hooking functions correctly.
For example, a program called SetWindowsHookExW as below:
SetWindowsHookExW(WH_KEYBOARD_LL, FuncA, hMod, 0);
My code can get the address of FuncA correctly, but I don't know how
to
invoke it. Because FuncA is in another process, I can't invoke it
directly. I
have tried PerformCallback4, it could run, but the device hung after
servral
times of invoking it.
Can anybody help me?
.
- Follow-Ups:
- Re: How to implement callback?
- From: mygogo
- Re: How to implement callback?
- References:
- Re: How to implement callback?
- From: Barry Bond [MS]
- Re: How to implement callback?
- From: Paul G. Tobey [eMVP]
- Re: How to implement callback?
- From: mygogo
- Re: How to implement callback?
- Prev by Date: Re: Booting from Local Image
- Next by Date: MMU is not initialized(VA to PA is not working)
- Previous by thread: Re: How to implement callback?
- Next by thread: Re: How to implement callback?
- Index(es):
Relevant Pages
|
Loading