Manage.cpp
上传用户:sz0451
上传日期:2022-07-29
资源大小:256k
文件大小:1k
- // This is the main project file for VC++ application project
- // generated using an Application Wizard.
- #include "stdafx.h"
- #include <gcroot.h>
- #using <mscorlib.dll>
- using namespace System;
- using namespace System::Runtime::InteropServices;
- __gc class MClass
- {
- public:
- int val;
- MClass(int n) { val = n; }
- };
- class UClass
- {
- public:
- gcroot<MClass*> mc;
- UClass(MClass* pmc)
- {
- mc = pmc;
- }
- int getValue()
- {
- return mc->val;
- }
- };
- // This is the entry point for this application
- #ifdef _UNICODE
- int wmain(void)
- #else
- int main(void)
- #endif
- {
- Console::WriteLine(S"Testing...");
- // Create a managed object
- MClass* pm = new MClass(3);
- // Create an unmanaged object
- UClass uc(pm);
- int v = uc.getValue();
- Console::WriteLine("Value is {0}", __box(v));
- return 0;
- }