.net实例:使用C++调用C#的DLL
1 创建C# DLL,需要指定应用类型为“类库”,代码:
namespace CSLib
{
public class Class1
{
private string name;
public string Name
{
get
{
return name;
}
set
{
name = "Your Name: " + value;
}
}
}
}
2 C++客户程序,是个控制台应用,代码:
#using "..\debug\CSLib.dll"
using namespace CSLib;
int _tmain(int argc, _TCHAR* argv[])
{
Class1 ^c = gcnew Class1();
c->Name = "zzj";
printf("%s\n", c->Name);
return 0;
}
3 几点要记住:
1 使用#using引用C# DLL,而不是#include。我就是想当然的使用了后者,所以浪费了一上午的时间;
2 别忘了using namespace CSLib;
3 使用C++/clr语法,采用正确的访问托管对象,即:使用帽子''^'',而不是星星''*''。
相关文档:
一、Access从Excel中导入数据
1.用到的Excel表的格式及内容
实现
OleDbConnection con = new OleDbConnection();
try
{
OpenFileDialog openFile = new OpenFileDialog();//打开文件对话框。
openFile.Filter = ("Excel 文件(*.xls)|*.xls") ......
关于使用到了两个C#关键字this和base。
1,C# "this " keyword
其作用引用类的当前实例,其实看了下面这个例子就好理解了。
主要三个作用:当前实例、参数传递和索引器
1.1 当前实例
class Team
{
///成员变量
private string name;
///构造函数
......
动态加载DLL需要使用Windows API函数:LoadLibrary、GetProcAddress以及FreeLibrary。我们可以使用DllImport在C#中使用这三个函数。
[DllImport("Kernel32")]
public static extern int GetProcAddress(int handle, String funcname);
[DllImport("Kernel32")]
public static extern int L ......
C#开发WPF/Silverlight动画及游戏系列教程(Game Tutorial):目录
本系列教程的示例代码下载(感谢 银光中国 提供资源分流):
第一部分源码:WPFGameTutorial_PartI(1-20节)
第二部分源码:WPFGameTutorial_PartII(21-26节)
第三部分源码:WPFGameTutorial_PartIII(27-30节)
第四部分源码:WPFGameTutorial_PartI ......