Error in creating a Gdiplus::Image

Good afternoon all! I have been working on an engine in C++ using the WIN32 API and GDIPlus. I have encountered an error in creating Gdiplus::Image()'s. Here is the offending piece of code:

RenderComponent* rend = new RenderComponent(o->GetID(), Gdiplus::Image(L"res/Player.bmp"));

The problem chunk is bolded, that is, the image constructor. Here is my error (it's rather non-cryptic):

error: 'Gdiplus::Image::Image(const Gdiplus::Image&)' is private


Now, obviously C++ is angry that I'm attempting to access a private function. I must be accessing the wrong function, as a code snippet a friend gave me read as:

Image imgWater(water);

Where water was a wchar_t to a file location, and this piece of code worked without error. I have consulted a few people, and they all think this is very abnormal. My IDE is Code::Blocks, compiler is minGW, and libgdiplus.a is linked.

Does anybody know what could be the issue? Thank you for your time!
Last edited on
They don't want you copying Images. The reason why the other code works is because the normal constructor is called, but in your first example you are creating an object then copying it.
You should take a reference or a pointer from the RenderComponent constructor. No other way will work.
But for your use you should take a wchar_t* instead of the image.

Now that I am from pc, let me explain you why:

1
2
3
4
5
// Suppose your constructor looks like:
RenderComponent::RenderComponent( unsigned ID, Gdiplus::Image image )
{
   //...
}

What's wrong is, in that line, no matter what, 'image' is a copy of the variable you input. Windows does not want you to copy an image like that, so, to solve this problem, you can take a reference.
But to store the texture, you will have to make another copy, and you cannot.
So you should use something like:
1
2
3
4
RenderComponent::RenderComponent( unsigned ID, const wchar_t * ImagePath ) : MyImageInTheClass( ImagePath )
{
   //...
}

And use it like:
 
new RenderComponent( o->GetID(), L"res/Player.bmp");

(MyImageInTheClass is a Gdiplus::Image)
Remember that you cannot copy objects of type RenderComponent, unless you are copying a pointer and/or using reference counting.

Also note that GDI/GDI+ haven't been built to make games, but simple graphics instead. You should use something hardware-accelerated to make things faster, like OpenGL/D3D/D2D1.
Last edited on
Thank you for your replies, I think you are correct EssGeEich. I am using a friends Component Based Engine to test out some AI, and not to actually make a game. I will respond on how your fix worked.
I'll be tuned.

If you can't get it to work, post the RenderComponent's declaration, i'll show you step-by-step.
I was actually having an error a week ago that I tried to fix by doing this. I followed your advice, and I'm back to that error :p. I posted the new problem in /windows/ again.
Topic archived. No new replies allowed.