虽然有 "使用InteropServices",但缺少DLLImport。

问题描述 投票:23回答:2

我有以下代码。

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?)

大多数人在网上找到的解决方案是 "使用System.Runtime.InteropServices;"但我有它。

c# dll
2个回答
33
投票

它是 DllImportDLLImport

:)


63
投票

尝试添加

using System.Runtime.InteropServices;

到你的类中,这就是你的类的命名空间 DllImportAttribute 居住在:

© www.soinside.com 2019 - 2024. All rights reserved.