您好,登錄后才能下訂單哦!
c#調(diào)用c++寫成的dll文件
首先是c++寫的聲明文件
// Inclusion guard
#ifndef _DLLTUT_DLL_H_
#define _DLLTUT_DLL_H_
// Make our life easier, if DLL_EXPORT is defined in a file then DECLDIR will do an export
// If it is not defined DECLDIR will do an import
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#else
#define DECLDIR __declspec(dllimport)
#endif
// Specify "C" linkage to get rid of C++ name mangeling
extern "C"
{
// Declare 2 functions
DECLDIR int Add( int a, int b );
DECLDIR void Function( void );
}
// End the inclusion guard
#endif
測試程序的目錄結(jié)構(gòu)
測試代碼c#
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication30
{
class Program
{
static void Main(string[] args)
{
test.Function();
Console.WriteLine("result: " + test.Add(2, 3).ToString());
Console.ReadLine();
}
}
class test
{
[DllImport("..\\..\\lib\\DLLTest.dll")]
public static extern void Function();
[DllImport("..\\..\\lib\\DllTest.dll")]
public static extern int Add(int i,int j);
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。