我正在为以下本机c ++类完成我的c ++ / CLI包装器:
#ifndef __TV3DENGINE_H__
#define __TV3DENGINE_H__
#pragma once
#include "TV3DMoteur.h"
#include "Input.h"
#include "Area.h"
#include <vcclr.h>
class Engine3D
{
public:
CLTV3DMoteur* clTV3D;
CLInput* clInput;
CLArea* clArea;
CLGlobalVar * clGlobalVar;
Engine3D();
~Engine3D();
void Setup(HWND TVScreenHWND, string PathString);
void UpdateLoop();
void Cleanup();
bool AppStillIdle();
CLTV3DMoteur* GetTV3D();
CLInput* GetInput();
CLArea* GetArea();
CLGlobalVar * GetGlobalVar();
};
#endif
Engine3D的实际构造函数是:
Engine3D::Engine3D()
{
clTV3D = CLTV3DMoteur::getInstance();
clInput = CLInput::getInstance();
clArea = CLArea::getInstance();
clGlobalVar = CLGlobalVar::getInstance();
}
这是实际的包装器:
#ifndef __WRAPPER_H__
#define __WRAPPER_H__
#pragma once
#include "TV3DEngine.h"
#include <msclr\marshal_cppstd.h>
public ref class Engine3DWrapper {
Engine3D* m_nativeClass;
public:
Engine3DWrapper() { m_nativeClass = new Engine3D(); }
~Engine3DWrapper() { delete m_nativeClass; }
void Setup(System::IntPtr tvscreen, System::String^ AppPath) {
System::String^ managedPath = AppPath;
m_nativeClass->Setup((HWND)tvscreen.ToInt32(), msclr::interop::marshal_as<std::string>(managedPath));
}
void UpdateLoop() {
m_nativeClass->UpdateLoop();
}
void Cleanup() {
m_nativeClass->Cleanup();
}
bool AppStillIdle() {
return(m_nativeClass->AppStillIdle());
}
protected:
!Engine3DWrapper() { delete m_nativeClass; }
};
#endif
我的问题是如何修改我的Wrapper以便我可以访问,例如,Engine3DWrapper-&gt; clGlobalVar-&gt; BLABLABLA()其中BLABLABLA将是CLGlobalVar c ++单例中定义的所有不同方法?
我试过这种技术:
property String ^Name
{
String ^get()
{
return gcnew String(_stu->getName());
}
}
但这似乎不可能,因为我不需要返回已定义的类型。
感谢您的帮助。
答案 0 :(得分:1)
问题解决了。 以下是Rufflewind建议后更正的Wrapper:
#ifndef __WRAPPER_H__
#define __WRAPPER_H__
#pragma once
#include "TV3DEngine.h"
#include <msclr\marshal_cppstd.h>
public ref class Engine3DWrapper {
Engine3D* m_nativeClass;
public:
Engine3DWrapper(System::IntPtr tvscreen, System::String^ AppPath)
{
m_nativeClass = new Engine3D((HWND)tvscreen.ToInt32(), msclr::interop::marshal_as<std::string>(AppPath));
m_TV3D = m_nativeClass->GetTV3D();
m_Input = m_nativeClass->GetInput();
m_Area = m_nativeClass->GetArea();
m_GlobalVar = m_nativeClass->GetGlobalVar();
}
~Engine3DWrapper() {
delete m_nativeClass;
}
void UpdateLoop() {
m_nativeClass->UpdateLoop();
}
void Cleanup() {
m_nativeClass->Cleanup();
}
bool AppStillIdle() {
return(m_nativeClass->AppStillIdle());
}
CLTV3DMoteur* m_TV3D;
CLInput* m_Input;
CLArea* m_Area;
CLGlobalVar* m_GlobalVar;
protected:
!Engine3DWrapper() { delete m_nativeClass; }
};
#endif
在本机类中使用简单的Get方法:
CLGlobalVar *Engine3D::GetGlobalVar()
{
clGlobalVar = CLGlobalVar::getInstance();
return(clGlobalVar);
}
谢谢你的帮助!