Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Estauns

Win32 Objects : Releasing / Deleting / When / Where / Why?

This topic is 5330 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m a litle confused on when you delete an object and when you release an object and things, with win32. In the Win32 tutorial at GAmeTutorials, during the unloading, you do something like this:
	// We made a backbuffer, clean it all up.

	if(m_hOldBITMAP)
	{
		// Select back the original surface.

		SelectObject(m_hBackDC, m_hOldBITMAP);

		// Delete Our Backbuffer.

		DeleteObject(m_hBackBITMAP);
		DeleteDC(m_hBackDC);
	}

	// If we have a DC, release it.

	if(m_hPrimaryDC)
		ReleaseDC(m_hWnd, m_hPrimaryDC);
Why do you release the Primary Buffer DC but delete the Back Buffer DC? Also, with that SelectObject(m_hBackDC, m_hOldBITMAP), why do you delete the m_hBackBITMAP but not the m_hOldBITMAP? I''m a little confused here, and GameTutorials.com is bollocks for explaining anything.

Share this post


Link to post
Share on other sites
Advertisement
You call ReleaseDC() when you got the device context by calling GetDC() or GetWindowDC().

You call DeleteDC() when you got the device context by calling CreateDC().

They probably used DeleteObject() on m_hBackBITMAP because they used CreateBitmap() (or one of its relatives) to create it.

The SelectObject() call is because before you delete a device context you should restore it''s original handles. In this case m_hOldBITMAP was probably the original bitmap object in the device context.

Share this post


Link to post
Share on other sites
If you are unsure if you should release or if you should delete simply check the MSDN documentation of the function you used to create the resource. It will tell you how to clean that resource up.

The reason you dont delete m_hOldBITMAP is because you didn''t create it. It was given to you and you must put it back.


Colin Jeanne | Invader''s Realm

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!