在 c# 裡存取系統 dll 檔案時,遇到傳回錯誤訊息:
The type or namespace name ‘DllImport’ could not be found
範例程式:
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);
...
說明:
1:一定要 using System.Runtime.InteropServices;
2: [DllImport(“GeoUrbanApp.exe”)] 的放置位置要在 class 裡,而不是 namespace 的第1層。