C++、C#互调用之C++ 调用C# dll (转载)
2014-07-10 16:16
375 查看
1、c# 创建dll
建立C#编写的DLL程序AddDll,项目类型为:类库
程序代码:
2、C++编写调用程序
建立C++的Win32控制台应用程序UseDll,项目类型为:Win32控制台应用程序
配置:右键点击解决方案资源管理器中的UseDll,选择“属性”,将公共语言运行库支持设置为“公共语言运行库支持(/clr)”
程序代码:
//gcnew creates an instance of a managed type (reference or value type) on the garbage
//collected heap. The result of the evaluation of a gcnew expression is a handle (^) to
//the type being created.
建立C#编写的DLL程序AddDll,项目类型为:类库
程序代码:
using System; using System.Collections.Generic; using System.Text; namespace AddDll { public class Add { public int iadd(int a, int b) { int c = a + b; return c; } } }
2、C++编写调用程序
建立C++的Win32控制台应用程序UseDll,项目类型为:Win32控制台应用程序
配置:右键点击解决方案资源管理器中的UseDll,选择“属性”,将公共语言运行库支持设置为“公共语言运行库支持(/clr)”
程序代码:
#include "stdio.h" #using "..\debug\AddDll.dll" using namespace AddDll; int main()
{ int result; Add ^add = gcnew Add(); //生成托管类型
//gcnew creates an instance of a managed type (reference or value type) on the garbage
//collected heap. The result of the evaluation of a gcnew expression is a handle (^) to
//the type being created.
result = add->iadd(10,90); printf("%d",result); scanf("%s"); return 0; }
相关文章推荐
- 使用C++调用C#的DLL(转载)
- 在VS2008环境下编写C语言DLL,并在C++和C#项目下调用 (转载)
- C# 调用C++ DLL 的类型转换(转载版)
- 【转载】Unity C# 调用C++ dll 问题集锦
- 转载:C#调用c++的dll
- C# 调用C++ DLL 的类型转换(转载版)
- C# 调用C++ DLL 的类型转换(转载版)
- 【转载】C#调用C++ DLL
- 转载在 C# 中调用 C++
- C#中调用C++的dll的参数为指针类型的导出函数
- C#调用C++编写的COM DLL
- C#调用C++编写的COM DLL
- 在C#里面调用带有回调函数和自定义结构体的DLL的例程——转载
- (转载)C#程序实现动态调用DLL的研究
- c#调用C++的DLL找不到入口点
- 转载一篇C++如何调用C#的文章
- C#调用C++编写的COM DLL
- C#调用api,或C++生成的dll
- 使用C++调用C#的DLL
- C#程序实现动态调用DLL的研究(转载)