29

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:

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.

4

2 回答 2

80

尝试添加

using System.Runtime.InteropServices;

对于您的班级,这就是DllImportAttribute所在的命名空间。

于 2013-07-21T06:02:26.397 回答
40

DllImport不是DLLImport

:)

于 2012-09-03T08:41:26.173 回答