user3876224
user3876224

Reputation: 3

PIVOKE Stackimbalance error

Hello I was wondering what is wrong with this PINVOKE declaration? I am not finding the mistake.

This is the Code in C++

BOOL HOOKDLL_API WINAPI SetHook(int HookType, BOOL bInstall,
                                    DWORD dwThreadId = 0,
                                    HWND hWndCaller = NULL);

This is my declaration:

[
        DllImport("CppHookDll.dll", CharSet = CharSet.Auto,
        //EntryPoint="?SetHook@@YGHHHKPAUHWND__@@@Z",
        EntryPoint = "SetKeyboardHook",
        ExactSpelling = true,CallingConvention=CallingConvention.StdCall)
    ]

    public static extern bool SetHook(int HookType, bool bInstall, [MarshalAs(UnmanagedType.U4)] UInt32 dwThreadId, IntPtr hWndCaller);

Thankt in advance.

Upvotes: 0

Views: 90

Answers (1)

David Heffernan
David Heffernan

Reputation: 612993

It looks like you are just importing the wrong function. The function in the unmanaged code is named SetHook, but you are importing a function named SetKeyboardHook. Presumably the function SetKeyboardHook has a different signature which would explain the stack imbalance warning.

Upvotes: 1

Related Questions