Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Managed C++ problem.

Started by PinguinDude Dec 26, 2004 at 5:53 AM 4 replies 1.1k views
Original Post
PinguinDude
PinguinDude
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:

	/*==============================================*/
	//
	// 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;

	};

Without pointer gives this error:

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;

	};

http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
RenZimE
RenZimE
well pinguindude PXImage cant not be a pointer unless its a value type
as for it saying it cant convert 'this' from PXImage to PXImage& it looks more like thats inside the PXImage Class its self.

(sorry if this is a useless post)
just woke up after a night of drinking :|
PinguinDude
PinguinDude
Ok ;) But I also don't understand the problem. I thought it would work but....
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
PinguinDude
PinguinDude
anyone?
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)
SiCrane
SiCrane
Did you declare PXImage as __gc?
PinguinDude
PinguinDude
no, PXImage is just a NORMAL C++ Class.
http://sourceforge.net/projects/pingux/ <-- you know you wanna see my 2D Engine which supports DirectX and OpenGL or insert your renderer here :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.