c#调用c++写成的dll文件
2012-06-04 23:32
281 查看
c#调用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
测试程序的目录结构
测试代码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);
}
}
本文出自 “好了,是我” 博客,请务必保留此出处http://huangchaosuper.blog.51cto.com/5221102/887532
首先是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
测试程序的目录结构
测试代码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);
}
}
本文出自 “好了,是我” 博客,请务必保留此出处http://huangchaosuper.blog.51cto.com/5221102/887532
相关文章推荐
- c#调用c++写成的dll文件
- 关于c++和C#如何调用自己用c++写的dll文件
- (转)VS2010 C#调用C++ DLL文件(图文讲解)
- C#调用C++dll文件 运行提示找不到函数的入口点
- (转)VS2010 C#调用C++ DLL文件(图文讲解)
- c++调用c#托管dll文件方法
- .Net 环境下C# 通过托管C++调用本地C++ Dll文件
- C#调用C++编译生成的dll文件
- c#调用 c++的dll文件
- VS2010 C#调用C++ DLL文件(图文讲解)
- C++怎么调用C#生成的dll文件
- VS2010 C#调用C++ DLL文件(图文讲解)
- C#中调用C++写的dll文件
- C#调用C++dll文件获取数据得到乱码的解决方法
- C#调用C++的dll文件方法
- c#调用c++写成的dll文件
- c#调用c++写成的dll文件,返回char*,返回数组,用ref接收,byte[] (zz)
- VS2010 C#调用C++ DLL文件(图文讲解)
- 如何生成DLL文件并导出函数及如何在C++或C#中调用DLL中导出的函数
- C# 调用 C++的dll文件时,参数对照