Click recorder in cf

P

Paul G. Tobey [eMVP]

Yes, I don't think that your application is being called in the same context
exactly, because the pointer has a different value than what you passed to
GWES to register the hook, but that's how I read the code, at least.
They're probably mapping the pointer to kernel space, then back to
application space, then passing it.

Yes, that's true and I hadn't thought of the pinning issue.

Paul T.

Oh fun, so you pass it in and it gets passed back filled out later. That
means that struct better be pinned or you're going to get all sorts of
non-reproduceable crashes in the field when you get GC compaction that
moves it.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com



"Paul G. Tobey [eMVP]" <p space tobey no spam AT no instrument no spam DOT
com> wrote in message news:[email protected]...
I've checked the GWES source code. The lparam parameter to the hook
callback does appear to be a pointer to the EVENTMSG structure that you
passed to the hooking function (so don't let that be deleted while you're
still using it!)

Yes, your application is going to be slower. You're seeing every single
message to every application before they go into any queue and,
therefore, you're causing all messages in the system to be serialized.
You do also have to CallNextHook in order to assure that the hooking
stack is handled correctly. It does work, although as I think we've
said, it's not for general use.

Paul T.
 
T

techiechic

What does the struct better be pinned means? I also CallNextHook after
I log the messages i received so I'm sure its not piling in my hook.
 
G

Guest

The fact you're asking what pinning is brings me back to my original
recommendation froma couple posts back that you really need to do more work
to really understand how marshaling works. You're trying to do some fairly
complex stuff without understanding some fundamentals. It's like trying to
build a race car without understanding how an engine works.
 
T

techiechic

Thanks for all your input. I'll read more on marshalling, and try
pinning the struct. I'll give update on what happened. Thanks again. :)
 
P

Paul G. Tobey [eMVP]

Don't forget that you can't just pin it ('fixed') for the execution time of
some single method of the application. You need to pin it in place for the
entire time between when you install the hook and when you remove the hook.
It can *never* move during that time (the only way I know of to do this is
to allocate the memory for the structure using native APIs like LocalAlloc,
although there are probably some others).

Paul T.
 
Joined
Feb 19, 2009
Messages
3
Reaction score
0
Hi All,

I tried to implement as follows:

public static void init_hook()
{
EVENTMSG myHookMessage = new EVENTMSG();
myHookMessage.message = 0;
myHookMessage.paramH = 0;
myHookMessage.time = 0;

GCHandle gc1 = GCHandle.Alloc(myHookMessage, GCHandleType.Pinned);
GCHandle gc2 = GCHandle.Alloc(MouseHookProcedure, GCHandleType.Pinned);
GCHandle gc3 = GCHandle.Alloc(hHook, GCHandleType.Pinned);

hHook = QASetWindowsJournalHook(0, MouseHookProcedure, ref myHookMessage);
}

Almost GCHandle everything but my result is still partial fail.
If this application is running on top screen, the program work well.

If mouse click to other program ( ex: calendar, time, control, setting ... etc ), as long as ppc need to run another program/application the while system will crash.

I also tried to package the while hook control into a DLL, but result is the same.
Please help.

Best regards,
Michael.

A class-scoped GCHandle (pointing to a class-scoped struct of course) would
work.


--

Chris Tacke, eMVP
Join the Embedded Developer Community
http://community.opennetcf.com


"Paul G. Tobey [eMVP]"
com> wrote in message news:[email protected]...
> Don't forget that you can't just pin it ('fixed') for the execution time
> of some single method of the application. You need to pin it in place for
> the entire time between when you install the hook and when you remove the
> hook. It can *never* move during that time (the only way I know of to do
> this is to allocate the memory for the structure using native APIs like
> LocalAlloc, although there are probably some others).
>
> Paul T.
>
> "techiechic" wrote in message
> news:[email protected]...
>> Thanks for all your input. I'll read more on marshalling, and try
>> pinning the struct. I'll give update on what happened. Thanks again. :)

>
>
 

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