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. Error 998 on Windows API Call

Error 998 on Windows API Call

Scheduled Pinned Locked Moved C#
csharpc++comjsonperformance
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.
  • T Offline
    T Offline
    TyronX
    wrote on last edited by
    #1

    The TrackMouseEvent function fails and returns zero. So I called (as msdn advised me) GetLastError() to get the error msg and it returns 998 which means: ERROR_NOACCESS Invalid access to memory location. Has anyone a clue what my OS is trying to tell me here? I guess the error is caused by the c++ struct which the function takes as parameter. ( TRACKMOUSEEVENT Struct on MSDN ) [DllImport("kernel32.dll", SetLastError=true)] static extern int GetLastError (); [DllImport("user32")] public static extern bool TrackMouseEvent(TRACKMOUSEEVENT lpEventTrack); [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)] public struct TRACKMOUSEEVENT { public long cbSize; public long dwFlags; public long hwndTrack; public long dwHoverTime; } and in the C# App Constructor: TRACKMOUSEEVENT foo = new TRACKMOUSEEVENT(); foo.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT)); foo.dwFlags = TME_NONCLIENT; foo.hwndTrack = (long)this.Handle; bool bar = TrackMouseEvent(foo); MessageBox.Show(""+GetLastError());

    D 1 Reply Last reply
    0
    • T TyronX

      The TrackMouseEvent function fails and returns zero. So I called (as msdn advised me) GetLastError() to get the error msg and it returns 998 which means: ERROR_NOACCESS Invalid access to memory location. Has anyone a clue what my OS is trying to tell me here? I guess the error is caused by the c++ struct which the function takes as parameter. ( TRACKMOUSEEVENT Struct on MSDN ) [DllImport("kernel32.dll", SetLastError=true)] static extern int GetLastError (); [DllImport("user32")] public static extern bool TrackMouseEvent(TRACKMOUSEEVENT lpEventTrack); [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)] public struct TRACKMOUSEEVENT { public long cbSize; public long dwFlags; public long hwndTrack; public long dwHoverTime; } and in the C# App Constructor: TRACKMOUSEEVENT foo = new TRACKMOUSEEVENT(); foo.cbSize = Marshal.SizeOf(typeof(TRACKMOUSEEVENT)); foo.dwFlags = TME_NONCLIENT; foo.hwndTrack = (long)this.Handle; bool bar = TrackMouseEvent(foo); MessageBox.Show(""+GetLastError());

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      TyronX wrote: [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)] public struct TRACKMOUSEEVENT { public long cbSize; public long dwFlags; public long hwndTrack; public long dwHoverTime; } Well, according to the docs, these four fields should be DWORDS, or unsigned 32-bit integers. In your C# code, you're using long, which is a 64 bit signed integer. Change your long's to int's or uint's and it should work. Also, change your hwndTrack type from long to IntPtr. Then it should work.

      [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)]
      public struct TRACKMOUSEEVENT {
      public int cbSize;
      public int dwFlags;
      public IntPtr hwndTrack;
      public int dwHoverTime;
      }

      RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      T 1 Reply Last reply
      0
      • D Dave Kreskowiak

        TyronX wrote: [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)] public struct TRACKMOUSEEVENT { public long cbSize; public long dwFlags; public long hwndTrack; public long dwHoverTime; } Well, according to the docs, these four fields should be DWORDS, or unsigned 32-bit integers. In your C# code, you're using long, which is a 64 bit signed integer. Change your long's to int's or uint's and it should work. Also, change your hwndTrack type from long to IntPtr. Then it should work.

        [StructLayout( LayoutKind.Sequential,CharSet=CharSet.Ansi)]
        public struct TRACKMOUSEEVENT {
        public int cbSize;
        public int dwFlags;
        public IntPtr hwndTrack;
        public int dwHoverTime;
        }

        RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        T Offline
        T Offline
        TyronX
        wrote on last edited by
        #3

        Thanks for your Answer but I still get the same Error Message (with your TRACKMOUSEEVENT structure) :/

        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