#include <gcroot.h>
是与 Microsoft 的 Managed Extensions for C++ 相关的头文件。它提供了一个名为 gcroot
的模板类,用于在使用 Common Language Runtime (CLR) 支持的 C++ 代码中声明托管对象的引用。gcroot
类允许您创建对托管对象的句柄,有助于在本地 C++ 代码和托管 .NET 代码之间建立连接。
#include <gcroot.h>
#include <msclr/auto_gcroot.h>
// 声明对 Class1^ 的托管句柄
gcroot<ClassLibrary3::Class1^>* Robot = new gcroot<ClassLibrary3::Class1^>;
void CMFCApplication2Dlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
// 使用新的 Class1^ 初始化 Robot
*Robot = gcnew ClassLibrary3::Class1();
(*Robot)->ConnectRobot();
}