JumpyNET Posted June 3, 2005 Posted June 3, 2005 (edited) I'm trying to declare the mouse_event API in C# 2005 Express. What's wrong? [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); And I get the following error: Error 1 The type or namespace name 'DllImport' could not be found (are you missing a using directive or an assembly reference?) Edited June 3, 2005 by JumpyNET Quote
Administrators PlausiblyDamp Posted June 3, 2005 Administrators Posted June 3, 2005 You are missing a using directive. add using System.Runtime.InteropServices; to the top of the file Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Wraith Posted June 4, 2005 Posted June 4, 2005 [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] public static extern void mouse_event(long dwFlags, long dx, long dy, long cButtons, long dwExtraInfo); Your types are the wrong size. the definition of mouse_event from the documentation is: VOID mouse_event( DWORD dwFlags, DWORD dx, DWORD dy, DWORD dwData, ULONG_PTR dwExtraInfo ); DWORD is an unsigned 32 bit integer, you're using long which is 64 bits and signed. The definitionof ULONG_PTR is debatable but i'd go with UIntPtr or IntPtr myself. I'd also say you can make the first type use a Flags marked enumeration of the values outlined in the documentation preventing lots of pointless casting internally once you've made the call. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.