簡體   English   中英

在c#代碼中導入DLL函數

[英]Importing DLL functions in c# code

我有一個DLL,我想在我的c#代碼中使用它的函數以下是該DLL的函數:

extern "C"
{
  __declspec(dllimport)
  const char* __stdcall ZAJsonRequestA(const char *szReq);

  __declspec(dllimport)
  const wchar_t* __stdcall ZAJsonRequestW(const wchar_t *szReq);

  __declspec(dllimport)
  const BSTR __stdcall ZAJsonRequestBSTR(BSTR sReq);
}

誰能告訴我如何在c#項目中使用它,因為這個dll似乎是用其他語言?

有關深入解釋,請查看以下有關代碼項目的文章

來自鏈接文章的小樣本如下所示

要調用函數,請說sayName

int __declspec(dllexport) methodName(int b)
{
      return b;
}

在c#中包含包含上述方法的類庫(MethodNameLibrary.dll),如下所示

class Program
{
   [DllImport(@"c:\MethodNameLibrary.dll")]
   private static extern int methodName(int b);
   static void Main(string[] args)
   {
       Console.WriteLine(methodName(3));
   }
}

使用DllImportMarshalAs屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM