Demo & Tutorial - Mixed with CLR
You can use HnxGC managed object mixed with Microsoft .NET platform objects. As in the following sample, 'p1' is a smart pointer to HnxGC object, and 'p2' is a .NET platform pointer to Ref object.
#include <stdio.h>
#include <string.h>
#include "hnxGC/hnxGC.h"
using namespace harnix;
#pragma managed(push, off)
class CFoo {
public:
CFoo() {
printf("native CFoo() %p\n", this);
}
~CFoo() {
printf("native ~CFoo() %p\n", this);
}
HNXGC_ENABLE(CFoo)
};
#pragma managed(pop)
ref class CBar {
public:
CBar() {
printf("CLR CBar() %p\n", this);
}
~CBar() {
printf("CLR ~CBar() %p\n", this);
}
};
int main()
{
lp<CFoo> p1 = gcnew CFoo();
#undef gcnew
CBar ^p2 = gcnew CBar();
p1 = nullptr;
p2 = nullptr;
return 0;
}
output: native CFoo() 003F2588 CLR CBar() 0106002C native ~CFoo() 003F2588