[DllImport("User32.dll"))有错误 [英] [DllImport("User32.dll")] have errors

查看:88
本文介绍了[DllImport("User32.dll"))有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#define DEBUG
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;



      static void Main(string[] args)
        {
            [DllImport("User32.dll")]
            // All errors from this ^|^
            //                       |
Error	1	} expected           C:\Program.cs	13	38	Project-229
Error	2	Invalid expression term ''[''	C:\Program.cs	13 13	Project-229
Error	3	; expected                    C:\Program.cs	13 14	Project-229
Error	4	; expected	                  C:\Program.cs	13 37	Project-229
Error	5	Invalid expression term '']''	C:\Program.cs	13 37	Project-229
Error	6	; expected	                  C:\Program.cs	13 38	Project-229

推荐答案

您要导入什么功能?

请查看http://www.pinvoke.net/以获取示例和此类示例.
What function are you trying to import?

Check out http://www.pinvoke.net/ for examples and such.


您的函数声明(与其他任何方法一样)都需要在类级别进行声明.您不能在其他方法中声明它们.

换句话说,在您的Main方法之外执行此操作.在调用本机函数时,标准是声明一个名为NativeMethods的类并将其放在其中.
Your function declarations (like any other methods) need to be declared at the class level. You cannot declare them within another method.

In other words, do it outside of your Main method. As you are calling native functions, the standard is to declare a class called NativeMethods and put them in there.


这篇关于[DllImport("User32.dll"))有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆