Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6622441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:24:22+00:00 2026-05-25T21:24:22+00:00

So as I understand it to implement RAII properly, if I where to call

  • 0

So as I understand it to implement RAII properly, if I where to call CreateFont, I’d wrap that in a class with CreateFont in the constructor and DeleteObject in the destructor, so it cleans it up when it goes out of scope.

First question is, won’t I end up with ALOT of classes doing that? Especially since the class only has a constructor and destructor.

Second question is, what if I’m calling the CreateFont class in the WndProc, that goes out of scope constantly. So am I supposed to do all my calls to CreateFont or like LoadBitmap in the WndMain?
I’m used to calling those functions in WM_CREATE and cleaning them up in WM_DESTROY.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:24:22+00:00Added an answer on May 25, 2026 at 9:24 pm

    You can avoid a lot of repetitious work by using a template to help you. For example if you use boost::shared_ptr you can do:

    #include <boost/shared_ptr.hpp>
    #include <functional>
    
    struct Font;
    
    Font *createFont();
    void deleteFont(Font*);
    
    int main() {    
      boost::shared_ptr<Font> font(createFont(), std::ptr_fun(deleteFont));
    }
    

    Which saves you writing a custom class to manage the resource. If boost and TR1 or newer aren’t available to you it’s still possible to implement something similar and generic yourself to assist.

    boost::shared_ptr is reference counted properly, so if you want to create it somewhere and “promote” it to live longer later you can do so by copying it somewhere longer lived before it dies.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand how to implement a StructureMap registry, my question concerns the fact that
Which browsers are able to understand and implement asterisk ( * ) in CSS
I have more or less been able to understand and implement all these concepts
I wanted to understand how we can implement a safe logout method in a
I don't understand why IList implements IEnumerable taking in consideration that IList implements ICollection
I'm currently trying to understand how to implement a 2-dimensional array of struct in
I am trying to understand how to implement MVC in winforms so I have
I know about jquery date-picker but cant understand how to implement it. Id like
I know about jquery date-picker but cant understand how to implement it inside a
I want to understand how to implement HTML5 <audio> fallback using Javascript... i.e. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.