raygeee
01-01-2009 14:10:52
Hello everyone,
currently I am trying to write a small wrapper for PagedGeometry and I'm having some difficulties with the language. Maybe some of you guys with C++ knowledge can help me out? Some of my problems seem to be a general understanding problem, not a specific bug.
I'm used to write code in VB.NET or C#, in C++/CLI I can at least understand the code but I'm not completely familiar with the syntax.
I've got the wrapper class MPagedGeometry which has the following code in it:
In my VB.NET class I call the following (I translated it to C# to make it easier):
When I call the first line (constructor), a new Forests::PagedGeometry instance gets created correctly as I can see in the debugger. The variable internalPagedGeometry is set. Now when I call the second line (SetCamera), I get an AccessViolationException. I understand the reason why this exception is thrown is because of the internal variable not set - the debugger tells me <undefined value>. But WHY is this? Why does the pointer loose the object? As far as I understand the code isn't very complicated. I tried to follow the wrapper patterns like in MET where it is exactly like that but working. Is it because of any specific C++/CLI environment setting?
My second problem is a pointer or cast issue:
The compiler complains about the cast in the first line of SetPageLoader. What's the correct syntax? I tried some ways but could'nt find the correct one.
I hope, someone can help me - would be very appreciated.
Cheers,
raygeee
currently I am trying to write a small wrapper for PagedGeometry and I'm having some difficulties with the language. Maybe some of you guys with C++ knowledge can help me out? Some of my problems seem to be a general understanding problem, not a specific bug.
I'm used to write code in VB.NET or C#, in C++/CLI I can at least understand the code but I'm not completely familiar with the syntax.
I've got the wrapper class MPagedGeometry which has the following code in it:
public ref class MPagedGeometry : System::IDisposable {
private:
Forests::PagedGeometry* internalPagedGeometry;
public:
MPagedGeometry(Mogre::Camera ^cam, float pageSize) {
Ogre::Camera* cm = (Ogre::Camera*)cam;
internalPagedGeometry = new Forests::PagedGeometry(cm, pageSize);
}
void SetCamera(Mogre::Camera ^cam) {
Ogre::Camera* cm = (Ogre::Camera*)cam;
internalPagedGeometry->setCamera(cm); <--crashes here with AccessViolationException
}
In my VB.NET class I call the following (I translated it to C# to make it easier):
MForests.MPagedGeometry trees = new MForests.MPagedGeometry();
trees.SetCamera(camera);
When I call the first line (constructor), a new Forests::PagedGeometry instance gets created correctly as I can see in the debugger. The variable internalPagedGeometry is set. Now when I call the second line (SetCamera), I get an AccessViolationException. I understand the reason why this exception is thrown is because of the internal variable not set - the debugger tells me <undefined value>. But WHY is this? Why does the pointer loose the object? As far as I understand the code isn't very complicated. I tried to follow the wrapper patterns like in MET where it is exactly like that but working. Is it because of any specific C++/CLI environment setting?
My second problem is a pointer or cast issue:
// MPagedGeometry.h:
void SetPageLoader(MPageLoader ^loader) {
Forests::PageLoader* pl = *loader->_GetNativePtr(); <--type cast compiler error C2440.
SetPageLoader(pl);
internalPagedGeometry->setPageLoader(pl);
pageLoader = gcnew MPageLoader((Forests::PageLoader*)internalPagedGeometry->getPageLoader());
}
// MPageLoader.h:
public ref class MPageLoader : System::IDisposable {
private:
Forests::PageLoader *pageLoader;
internal:
MPageLoader(Forests::PageLoader* pl) {
pageLoader = pl;
}
public:
Forests::PageLoader* _GetNativePtr() {
return pageLoader;
}
The compiler complains about the cast in the first line of SetPageLoader. What's the correct syntax? I tried some ways but could'nt find the correct one.
I hope, someone can help me - would be very appreciated.
Cheers,
raygeee