C++通过DLL调用C#代码
本文将介绍C++中通过DLL来调用C#代码。首先建立C#的“类库”工程CShapeDLL。然后输入如下代码:[csharp]//C++通过DLL调用C#代码//http://blog.csdn.net/morewindows/article/details/8678431//By MoreWindows( http://blog.csdn.net/MoreWindows )using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace CShapeDLL{public class CMyAddClass{private int m_nNumber1;private int m_nNumber2;public int Number1{set { m_nNumber1 = value; }get { return m_nNumber1; }}public int Number2{set { m_nNumber2 = value; }get { return m_nNumber2; }}public int AddFunc(){return m_nNumber1 + m_nNumber2;}}public class CMyWriteLine{private string m_strText;public string Text{set { m_strText = value; }get { return Text; }}public void WriteLineFunc(){Console.WriteLine(m_strText);}}}// By MoreWindows( http://blog.csdn.net/MoreWindows )//C++通过DLL调用C#代码//http://blog.csdn.net/morewindows/article/details/8678431//By MoreWindows( http://blog.csdn.net/MoreWindows )using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace CShapeDLL{public class CMyAddClass{private int m_nNumber1;private int m_nNumber2;public int Number1{set { m_nNumber1 = value; }get { return m_nNumber1; }}public int Number2{set { m_nNumber2 = value; }get { return m_nNumber2; }}public int AddFunc(){return m_nNumber1 + m_nNumber2;}}public class CMyWriteLine{private string m_strText;public string Text{set { m_strText = value; }get { return Text; }}public void WriteLineFunc(){Console.WriteLine(m_strText);}}}// By MoreWindows( http://blog.csdn.net/MoreWindows )这里有两个类,一个是MyAddClass类,是用来做加法运算的,另一个是CMyWriteLine,用来输出文本的。然后以C++控制台程序为例,C++代码如下:[cpp]//C++通过DLL调用C#代码//http://blog.csdn.net/morewindows/article/details/8678431#using "CShapeDLL\\CShapeDLL\\bin\\Debug\\CShapeDLL.dll"//#using "CShapeDLL\\CShapeDLL\\bin\\Release\\CShapeDLL.dll"#include <stdio.h>#include <conio.h>using namespace CShapeDLL;int main(){printf(" C++通过DLL调用C#代码\n");printf(" - By MoreWindows( http://blog.csdn.net/morewindows/article/details/8678431 ) -\n\n");CMyWriteLine ^ writeLineClass = gcnew CMyWriteLine;writeLineClass->Text = "使用C# 的CMyWriteLine示范";writeLineClass->WriteLineFunc();writeLineClass->Text = "By MoreWindows (http://blog.csdn.com/MoreWindows)";writeLineClass->WriteLineFunc();writeLineClass->Text = "http://blog.csdn.net/morewindows/article/details/8678431";writeLineClass->WriteLineFunc();printf("\n ---------------------------------- \n");CMyAddClass ^ addClass = gcnew CMyAddClass;addClass->Number1 = 3;addClass->Number2 = 5;printf("使用C# 的CMyAddClass示范\n");printf("%d + %d = %d\n", addClass->Number1, addClass->Number2, addClass->AddFunc());getch();return 0;}//By MoreWindows( http://blog.csdn.net/MoreWindows )//C++通过DLL调用C#代码//http://blog.csdn.net/morewindows/article/details/8678431#using "CShapeDLL\\CShapeDLL\\bin\\Debug\\CShapeDLL.dll"//#using "CShapeDLL\\CShapeDLL\\bin\\Release\\CShapeDLL.dll"#include <stdio.h>#include <conio.h>using namespace CShapeDLL;int main(){printf(" C++通过DLL调用C#代码\n");printf(" - By MoreWindows( http://blog.csdn.net/morewindows/article/details/8678431 ) -\n\n");&nb补充:软件开发 , C++ ,
上一个:题目1075: 特殊乘法
下一个:题目1126: 还是A+B
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊