尽管有"using InteropServices",但仍缺少DLLImport

31

我有以下代码:

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);
...

我正在尝试从.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?)

大多数人在网上找到的解决方案是 "using System.Runtime.InteropServices;" 但我已经有了。

2个回答

90
尝试在你的类中添加 using System.Runtime.InteropServices; ,这是 DllImportAttribute 所在的命名空间。

44

应使用DllImport而不是DLLImport

:)


嘿,谢谢,你是正确的!我从stackoverflow的一个答案中获取了它,显然这个人在他写的内容上没有谨慎。 - Vadiklk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接