Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 64 bit / IME / WindowsHook problem

64 bit / IME / WindowsHook problem

Scheduled Pinned Locked Moved C#
helpcsharpcomdebugging
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Daniel Grunwald
    wrote on last edited by
    #1

    I need help with a strange problem. Symptom: my C# application crashes with a AccessViolationException. The interesting thing is that it happens only when running as 32bit-process on 64-bit Windows. Running 32bit on 32bit works fine, so does 64bit on 64bit. FxCop does not complain about my P/Invoke declarations, so I don't think I confused IntPtr and int parameters - it runs fine both as 32bit process and 64bit process - just not as 32 bit process on Windows XP Professional x64 Edition. Using the managed debug assistent in VS05, I get the error message "The runtime has encountered a fatal error. The address of the error was at 0x79fccc04, on thread 0x6c8. The error code is 0xc0000005.". The line where it's failing is "return CallNextHookEx(...);", the callstack suggests it fails while/after calling CallNextHookEx; not when returning from my own hook procedure. What makes this really interesting is that the code using the hook is working fine until the text-editor portion of the app is activated. It crashes when the hook receives the message caused by activating the IME (input method editor; for asian languages). Here is the P/Invoke declaration for the hook (I'm creating the hook with code=WH_CALLWNDPROCRET, hInstance=IntPtr.Zero and threadID=AppDomain.GetCurrentThreadId()): internal delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")] internal static extern IntPtr SetWindowsHookEx(HookType code, HookProc func, IntPtr hInstance, int threadID); [DllImport("user32.dll")] internal static extern int UnhookWindowsHookEx(IntPtr hhook); [DllImport("user32.dll")] internal static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam); CallNextHookEx[^] definition from MSDN: LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam); And here is the P/Invoke declaration for the IME: private const int WM_IME_CONTROL = 0x0283; [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, [In, MarshalAs(UnmanagedType.LPStruct)] LOGFONT lParam); [ StructLayout(LayoutKind.Sequential) ] private class LOGFONT { public int lfHeight = 0; public int lfWidth =

    L 1 Reply Last reply
    0
    • D Daniel Grunwald

      I need help with a strange problem. Symptom: my C# application crashes with a AccessViolationException. The interesting thing is that it happens only when running as 32bit-process on 64-bit Windows. Running 32bit on 32bit works fine, so does 64bit on 64bit. FxCop does not complain about my P/Invoke declarations, so I don't think I confused IntPtr and int parameters - it runs fine both as 32bit process and 64bit process - just not as 32 bit process on Windows XP Professional x64 Edition. Using the managed debug assistent in VS05, I get the error message "The runtime has encountered a fatal error. The address of the error was at 0x79fccc04, on thread 0x6c8. The error code is 0xc0000005.". The line where it's failing is "return CallNextHookEx(...);", the callstack suggests it fails while/after calling CallNextHookEx; not when returning from my own hook procedure. What makes this really interesting is that the code using the hook is working fine until the text-editor portion of the app is activated. It crashes when the hook receives the message caused by activating the IME (input method editor; for asian languages). Here is the P/Invoke declaration for the hook (I'm creating the hook with code=WH_CALLWNDPROCRET, hInstance=IntPtr.Zero and threadID=AppDomain.GetCurrentThreadId()): internal delegate IntPtr HookProc(int code, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll")] internal static extern IntPtr SetWindowsHookEx(HookType code, HookProc func, IntPtr hInstance, int threadID); [DllImport("user32.dll")] internal static extern int UnhookWindowsHookEx(IntPtr hhook); [DllImport("user32.dll")] internal static extern IntPtr CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam); CallNextHookEx[^] definition from MSDN: LRESULT CallNextHookEx(HHOOK hhk, int nCode, WPARAM wParam, LPARAM lParam); And here is the P/Invoke declaration for the IME: private const int WM_IME_CONTROL = 0x0283; [DllImport("user32.dll")] private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, [In, MarshalAs(UnmanagedType.LPStruct)] LOGFONT lParam); [ StructLayout(LayoutKind.Sequential) ] private class LOGFONT { public int lfHeight = 0; public int lfWidth =

      L Offline
      L Offline
      LongRange Shooter
      wrote on last edited by
      #2

      You are trying to invoke a 64-bit dll in a 32-bit world.

      D 1 Reply Last reply
      0
      • L LongRange Shooter

        You are trying to invoke a 64-bit dll in a 32-bit world.

        D Offline
        D Offline
        Daniel Grunwald
        wrote on last edited by
        #3

        What 64-bit dll? I think I should add that I don't even have an IME installed - just some users of our software have. All P/Invoke calls are from user32.dll - it uses the 32bit version of that dll. When disabling the IME call (I personally don't need an IME, only some users do), everything works fine.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups