Original Post
Hey, I wrote a 2D Engine in C++ and I wanted it to work in .net too so I started a Managed C++ Dll. Now there is a small problem. I don't want image to be a pointer but when it is not a pointer i can't seem to use the var. With pointer compiles fine but crashes program: Without pointer gives this error:
/*==============================================*/
//
// PXNetImage .net wrapper class.
//
/*==============================================*/
public __gc class PXNetImage
{
public:
int DrawImage(int X, int Y, int Width, int Height)
{
return Image->DrawImage(X, Y, Width, Height);
}
int RotateImage(int Degrees)
{
return Image->RotateImage(Degrees);
}
int SetAlphaImage(int Alpha)
{
return Image->SetAlphaImage(Alpha);
}
int LoadImage(String *Filename)
{
// first convert strings
char* strFilename = (char*)(void*)Marshal::StringToHGlobalAnsi(Filename);
// get result.
int result = Image->LoadImage(strFilename);
// free strings
Marshal::FreeHGlobal(strFilename);
return 0;
}
private:
PXImage *Image;
};
error C2662: 'PXImage::DrawImage' : cannot convert 'this' pointer from 'PXImage' to 'PXImage &'
error C2662: 'PXImage::RotateImage' : cannot convert 'this' pointer from 'PXImage' to 'PXImage &'
error C2662: 'PXImage::SetAlphaImage' : cannot convert 'this' pointer from 'PXImage' to 'PXImage &'
error C2662: 'PXImage::LoadImageA' : cannot convert 'this' pointer from 'PXImage' to 'PXImage &'
/*==============================================*/
//
// PXNetImage .net wrapper class.
//
/*==============================================*/
public __gc class PXNetImage
{
public:
int DrawImage(int X, int Y, int Width, int Height)
{
return Image.DrawImage(X, Y, Width, Height);
}
int RotateImage(int Degrees)
{
return Image.RotateImage(Degrees);
}
int SetAlphaImage(int Alpha)
{
return Image.SetAlphaImage(Alpha);
}
int LoadImage(String *Filename)
{
// first convert strings
char* strFilename = (char*)(void*)Marshal::StringToHGlobalAnsi(Filename);
// get result.
int result = Image.LoadImage(strFilename);
// free strings
Marshal::FreeHGlobal(strFilename);
return 0;
}
private:
PXImage Image;
};