C# 即使有“使用 InteropServices”,也缺少 DLLImport
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12244533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Missing DLLImport even though there is a "using InteropServices"
提问by Vadiklk
I have the following code:
我有以下代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MapsApp.DB;
namespace MapsApp
{
public partial class _Default : System.Web.UI.Page
{
[DLLImport("GeoUrbanApp.exe")]
public static extern double CalcFigure(double east, double north, double size);
...
I am trying to call the CalcFigure function from the .exe. I've added it in the references, and trying to import it. All I get is:
我正在尝试从 .exe 调用 CalcFigure 函数。我已将其添加到参考文献中,并尝试导入它。我得到的是:
The type or namespace name 'DLLImport' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'DLLImportAttribute' could not be found (are you missing a using directive or an assembly reference?)
The solution most people find online is the "using System.Runtime.InteropServices;" but I have it.
大多数人在网上找到的解决方案是“使用 System.Runtime.InteropServices;” 但我有。
采纳答案by Kieren Johnstone
It's DllImportnot DLLImport
这DllImport不DLLImport
:)
:)
回答by Roz
Try adding
尝试添加
using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
to your class, that's the namespace the DllImportAttributeresides in.
对您的班级来说,这就是DllImportAttribute所在的命名空间。

