Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > .NET Languages
You last visited: Today at 08:01

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

Advertisement



[C#] CallbackOnCollectedDelegate-Exception

Discussion on [C#] CallbackOnCollectedDelegate-Exception within the .NET Languages forum part of the Coders Den category.

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 04/24/2010, 16:11   #2

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
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 04/24/2010, 17:26   #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 04/24/2010, 20:29   #4

 
x]vIrus[x's Avatar
 
elite*gold: 37
Join Date: Apr 2004
Posts: 2,154
Received Thanks: 250
ich hab auch win7 x64, und die testsolution funzt bei mir einwandfrei ,...
x]vIrus[x is offline  
Old 04/26/2010, 15:54   #5
 
scbiz's Avatar
 
elite*gold: 196
Join Date: Nov 2005
Posts: 625
Received Thanks: 192
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:
scbiz is offline  
Reply


Similar Threads Similar Threads
K2 Exception
01/15/2010 - Heroes of Newerth - 0 Replies
How can i solve that error? Help me pls
OllyDbg exception help
12/30/2009 - Mabinogi - 1 Replies
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 the first time I get the error, I'm using a Windows XP for the editting and it's working fine until today. The error is not fixed when I use Shift+F7/F8/F9. Help?
Global Exception(2)!!!
03/12/2009 - Silkroad Online - 0 Replies
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 'stealthex_error.log' file to stealthex.org and just behing that error theres one saying Global Exception(1)!!! i can't find a solution anywhere and theirs other people with this problem to, so your not only helping me but your helping others. thanks
dc all and exception to some players
01/11/2008 - Conquer Online 2 - 3 Replies
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 inputting the names f any1 can make it that be great :P
can anyone help with this unhandled exception?
03/21/2006 - Silkroad Online - 4 Replies
sro_client.exe(2160) - Unhandled Exception ACCESS_VIOLATION (0xc0000005) at address 0x10034a24 in module C:\Documents and Settings\user\Desktop\s robot\Silk.dll(2006-03-19:10-10-54). Registers: EAX 00000028 EBX 0000000A ECX 10929118 EDX 0012FC56 ESI 0012FC50 EDI 10929118 CS:EIP 0000001B:10034A24 SS:ESP 00000023:0012FBF8 EBP 00000023 C:\Documents and Settings\user\Desktop\s robot\Silk.dll at address: 10034a24 the sro_client.exe is 1,815,552 bytes



All times are GMT +2. The time now is 08:01.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.