背景:使用C#操縱鼠標進行重復性的工作
background: using Csharp to handle the keyboard or mouse to do the repetitive work.
問題:屬性“DllImport”在該聲明類型中無效。它只在“method”聲明中有效。錯誤 1 屬性“DllImport”在該聲明類
Question:attribution “DllImport” is invalid in the declaration, it is just valid in the “method” declaration
解決方案:使用外部調用的方法
Solution:Use the external method
code example:
private static extern int mouse_event(
int dwFlags,// 下表中標志之一或它們的組合
int dx,
int dy, //指定x,y方向的絕對位置或相對位置
int cButtons,//沒有使用
int dwExtraInfo//沒有使用
);
extern is used to declare the method implemented externally, it is often used in the situation that interop (using System.Runtime.InteropServices) to call unmanaged code in and DllImport is used at the same time. At that time the method should declard as static.