MFC中调用C#控件(转)

#include <afxwinforms.h>// MFC Windows Forms support
#using <system.dll>
#using <Microsoft.VisualC.Dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <mscorlib.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::ComponentModel;
using namespace Microsoft::VisualC::MFC;

using namespace stdcli::language;

以上是某些资料上说要引用的, 但是实际开发中视情况而定

下面是我自己测是的例子

#using <system.dll>
#using <Microsoft.VisualC.Dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
#using <mscorlib.dll>
#using "../debug/INCUserver.dll"  // C#编写的dll
using namespace INCUserver;  
using namespace System;


创建一个C#的类

frm_Server ^c = gcnew frm_Server();

c->Name = "zzj";

1 使用#using引用C# DLL,而不是#include。路径要注意设置正确
 2 别忘了using namespace INCUserver
 3 使用C++/clr语法,采用正确的访问托管对象,即:使用帽子'^',而不是星星'*',在项目->属性->配置属性->常规   ---->公共语言运行支持库->公共语言运行库支持(/clr).

否则不能调用C#的dll


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值