错误 1 属性“DllImport”在该声明类型中无效。它只在“method”声明中有效。

kiba518 2008-09-23 01:40:51
错误 1 属性“DllImport”在该声明类型中无效。它只在“method”声明中有效。 C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\WindowsApplication13\WindowsApplication13\Form1.cs 14 10 WindowsApplication13


这是什么错误 得怎么改啊

顺便问下[DllImport("user32")] 这么写对吗
USER32需要自己下吗
...全文
2296 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
dragon000000 2012-05-07
  • 打赏
  • 举报
回复
刚学,还没有弄清楚
baidutong 2011-05-27
  • 打赏
  • 举报
回复
第三代省份都
GhostAdai 2008-09-23
  • 打赏
  • 举报
回复
晕~又慢了!以后不同时打开那么多帖子了!
GhostAdai 2008-09-23
  • 打赏
  • 举报
回复
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);
--------------------------------------------
放这上面
ericzhangbo1982111 2008-09-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication13
{

public partial class Form1 : Form
{
[DllImport("user32")]
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

private readonly int MOUSEEVENTF_LEFTDOWN = 0x2;
private readonly int MOUSEEVENTF_LEFTUP = 0x4;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}


private void button1_Click(object sender, EventArgs e)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 10 * 65536 / 1024, 10 * 65536 / 768, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 10 * 65536 / 1024, 10 * 65536 / 768, 0, 0);


}
kiba518 2008-09-23
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsApplication13
{

public partial class Form1 : Form
{
[DllImport("user32")]
private readonly int MOUSEEVENTF_LEFTDOWN = 0x2;
private readonly int MOUSEEVENTF_LEFTUP = 0x4;

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, int dwExtraInfo);

private void button1_Click(object sender, EventArgs e)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 10 * 65536 / 1024, 10 * 65536 / 768, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 10 * 65536 / 1024, 10 * 65536 / 768, 0, 0);


}








这个是全体函数了
我该放哪呢
放哪 他好使
brallow 2008-09-23
  • 打赏
  • 举报
回复
对,这个attribute只能放到你声明的某一个方法的上面一行。
shalen520 2008-09-23
  • 打赏
  • 举报
回复
说的很清楚了,该标签只能放在方法上面
ericzhangbo1982111 2008-09-23
  • 打赏
  • 举报
回复
[DllImport("winmm.dll")]
private static extern bool Convert_Lambert_2_To_Geodetic(double Easting,
double Northing,
ref double Latitude,
ref double Longitude);


user32不需要
它调用的是系统的api

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧