Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 17:31

  • Please register to post and access all features, it's quick, easy and FREE!

 

[C#] CallbackOnCollectedDelegate-Exception

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jan 2010
Posts: 13
Received Thanks: 3
[C#] CallbackOnCollectedDelegate-Exception

Hallo epvp*^^

Ich versuch mich gerade in C# an globalen Maus- und Tastaturhooks. Der Tastatur-Hook funktioniert wie er soll, aber beim Maus-Hook habe ich ein Problem. Wenn man die Maus rumbewegt, nach dem man Hook aktiviert hat, gibt es plötzlich eine "CallbackOnCollectedDelegate-Exception".

Ich definiere ein Delegate, das ich dann der WinAPI-Funktion SetWindowsHookEx übergebe. Das Delegate wird auf Klassenebene deklariert, und im Konstruktor initialisiert. Trotzdem wird diese vom Garbage Collector eingesammelt und verursacht eine Exception, weil Windows die Funktion nicht mehr finden kann.

PHP Code:
class GlobalMouseHook    {
            [
UnmanagedFunctionPointer(System.Runtime.InteropServices.CallingConvention.StdCall)]
            public 
delegate int HookProc(int nCodeint wParamMouseHookStruct lParam);

            private 
HookProc _MouseHookProc;
            public const 
int WH_MOUSE_LL 14;

            public 
GlobalMouseHook()
            {
                       
_MouseHookProc = new HookProc(MouseHookProc);
            }

            private 
int MouseHookProc(int nCodeint wParamMouseHookStruct lParam)
            { ... }

            public 
bool Hook()
            {
                        
hHook SetWindowsHookEx(WH_MOUSE_LLMouseHookProc,(IntPtr)00);
                        if (
hHook == 0)
                        {
                            return 
false;
                        }
                        return 
true;
            }

            public 
bool UnHook()
            {
                        return 
UnhookWindowsHookEx(hHook);
            }

            [
DllImport("user32.dll"CharSet CharSet.Auto,
         
CallingConvention CallingConvention.StdCall)]
            public static 
extern int SetWindowsHookEx(int idHookHookProc lpfn,
        
IntPtr hInstanceint threadId);

            [
DllImport("user32.dll"CharSet CharSet.Auto,
         
CallingConvention CallingConvention.StdCall)]
            public static 
extern bool UnhookWindowsHookEx(int idHook);

            [
DllImport("user32.dll"CharSet CharSet.Auto,
         
CallingConvention CallingConvention.StdCall)]
            public static 
extern int CallNextHookEx(int idHookint nCode,
        
int wParamref MouseHookStruct lParam);

PHP Code:
[StructLayout(LayoutKind.Sequential)]
public class 
POINT
{
        public 
int x;
        public 
int y;
}

[
StructLayout(LayoutKind.Sequential)]
public class 
MouseHookStruct
{
        public 
POINT pt;
        public 
int hwnd;
        public 
int wHitTestCode;
        public 
int dwExtraInfo;

Ich hoffe ihr könnt mir helfen.

MfG,
noobyplay



n00byplay is offline  
Old   #2
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,156
Received Thanks: 250
dein moushookstruct is zu kurz, da fehlt ein int

[StructLayout(LayoutKind.Sequential)]
public class MouseHookStruct
{
public POINT pt;
public int mouseData;
public int flags;
public int time;
public IntPtr dwExtraInfo;
}

hier meine testsolution:
Attached Files
File Type: rar wMousehooktest.rar (38.7 KB, 2 views)


x]vIrus[x is offline  
Thanks
1 User
Old   #3
 
elite*gold: 0
Join Date: Jan 2010
Posts: 13
Received Thanks: 3
Vielen Dank für den Hinweis. Aber das Problem tritt immer noch auf, sogar bei deiner Test-Solution.

Ich hab Windows 7 64-bit, kann das damit zusammenhängen?

MfG,
noobyplay
n00byplay is offline  
Old   #4
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,156
Received Thanks: 250
ich hab auch win7 x64, und die testsolution funzt bei mir einwandfrei ,...


x]vIrus[x is offline  
Old   #5
 
elite*gold: 196
Join Date: Nov 2005
Posts: 629
Received Thanks: 191
Quote:
Originally Posted by x]vIrus[x View Post
ich hab auch win7 x64, und die testsolution funzt bei mir einwandfrei ,...
Zwar unschön programmiert, jedoch ändert das nichts an der Tatsache, dass es bei mir ebenfalls einwandfrei funktioniert:
You must register and activate your account in order to view images.


scbiz is offline  
Reply



« Previous Thread | Next Thread »

Similar Threads
K2 Exception
How can i solve that error? Help me pls
0 Replies - Heroes of Newerth
OllyDbg exception help
When I open a file (any file) with OllyDbg I get this error : Privileged instruction - use Shift+F7/F8/F9 to pass exception to program This is...
1 Replies - Mabinogi
Global Exception(2)!!!
I get this error when I'm at the stealthex login window, and as soon as i hit start this error comes up "Global Exception(2)!!! Send the...
0 Replies - SRO Ask the Experts
dc all and exception to some players
i knw it was possible before when coplus was working but im wondering f any1 can make a dc standalone and with an exception to some player just by...
3 Replies - CO2 Main - Discussions / Questions
can anyone help with this unhandled exception?
sro_client.exe(2160) - Unhandled Exception ACCESS_VIOLATION (0xc0000005) at address 0x10034a24 in module C:\Documents and...
4 Replies - SRO Main - Discussions / Questions



All times are GMT +1. The time now is 17:31.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Abuse
Copyright ©2017 elitepvpers All Rights Reserved.