Re: QASetWindowsJournalHook by managed code



Hi Chris,
Thanks for help, I changed code as follows but result is the same, regarding the leakage, I guess you mean the GCHandle never free in code, I guess it will OK because enough memory for leakage ... just to make sure everything should exist in memory all the time ....

public class Class1
{
public static int hHook = 0;
public static EVENTMSG myHookMessage = new EVENTMSG();
public static GCHandle gc1 = GCHandle.Alloc(myHookMessage, GCHandleType.Pinned);
public static GCHandle gc2 = GCHandle.Alloc(MouseHookProcedure, GCHandleType.Pinned);
public static GCHandle gc3 = GCHandle.Alloc(hHook, GCHandleType.Pinned);
....
public static void init_hook()
{
myHookMessage.hwnd = 0; ;
myHookMessage.message = 0;
myHookMessage.paramH = 0;
myHookMessage.time = 0;
hHook = QASetWindowsJournalHook(0, MouseHookProcedure, ref myHookMessage);
}

The Class1 was packaged to DLL then called from my application, I am not sure it will help or not.
or I should package Native C DLL to make sure no memory collection ?

I still can't get my application work .... please help, appreciate!

J.B.

"Chris Tacke, eMVP" <ctacke.at.opennetcf.dot.com> wrote in message news:eHeyiv4sJHA.4684@xxxxxxxxxxxxxxxxxxxxxxx
My guess is that the gchandle is going out of scope and getting collected. If not you still have a memory leak.


--

Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com

"Jack P" <private@xxxxxxxxxxxx> wrote in message news:%239cbS40sJHA.4632@xxxxxxxxxxxxxxxxxxxxxxx
Hi All,

I am trying QASetWindowsJournalHook() in c#, it works but having some problem.

I can receive the hooked message correctly ( mouse move, click, x , y ...etc ), but as long as I do something as below, the system (ppc) will crash.

1. Run my c# QASetWindowsJournalHook application, working.
2. Click [Start], my application is still working, message received well.
3. Click [Today] or [Setup] or [IE] ... whatever the next program is .... the while system will crash ( stop there then can't do anything .... )

public static int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
{
return CallNextHookEx(hHook, nCode, wParam, lParam);
}

I also tried to GCHandle everything but result is the same ...

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);
}

and I also tried to package the hook functions into a c# DLL ...

but result is the same ... will also crash ...

Can somebody help ?

Appreciate!
JB



.



Relevant Pages

  • Re: QASetWindowsJournalHook by managed code
    ... "Chris Tacke, ... Thanks for help, I changed code as follows but result is the same, regarding the leakage, I guess you mean the GCHandle never free in code, I guess it will OK because enough memory for leakage ... ... just to make sure everything should exist in memory all the time .... ... public static EVENTMSG myHookMessage = new EVENTMSG; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: QASetWindowsJournalHook by managed code
    ... Chris Tacke, Embedded MVP ... regarding the leakage, I guess you mean the GCHandle never free in code, I ... guess it will OK because enough memory for leakage ... ... public static EVENTMSG myHookMessage = new EVENTMSG; ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: QASetWindowsJournalHook by managed code
    ... My guess is that the gchandle is going out of scope and getting collected. ... Chris Tacke, Embedded MVP ... the while system will crash (stop there then can't do anything ... EVENTMSG myHookMessage = new EVENTMSG; ...
    (microsoft.public.dotnet.framework.compactframework)

Loading