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 178689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:16:30+00:00 2026-05-11T14:16:30+00:00

A wide range of structures is used in Win32 programming. Many times only some

  • 0

A wide range of structures is used in Win32 programming. Many times only some of their fields are used and all the other fields are set to zero. For example:

STARTUPINFO startupInfo; // has more than 10 member variables ZeroMemory( &startupInfo, sizeof( startupInfo ) ); //zero out startupInfo.cb = sizeof( startupInfo ); //setting size is required according to MSDN startupInfo.dwFlags = STARTF_FORCEOFFFEEDBACK; //Now call CreateProcess() passing the startupInfo into it 

I want to stop copy-pasting such code and instead use an abstraction that would care about zeroing and setting parameters. Let’s presume I only need the struct initialized as in example, and no other tuning is ever needed. Is the following a good solution? What are possible problems?

class CStartupInfo : public STARTUPINFO { public:    CStartupInfo()    {        ZeroMemory( this, sizeof( STARTUPINFO ) );        cb = sizeof( STARTUPINFO );        dwFlags = STARTF_FORCEOFFFEEDBACK;    } }; 

I’m in particular concerned about the ZeroMemory() call – looks like I fully control the code and the class has no vtable and calling ZeroMemory() this way is safe and there’s no big difference between the two code snippets except that the latter provides an abstraction. Are there any caveats?

  • 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. 2026-05-11T14:16:30+00:00Added an answer on May 11, 2026 at 2:16 pm

    I think this is a fine way to make such structures more bulletproof. I’m not sure why others seem to not like the technique. I use it occasionally, but not as often as I otherwise might because it doesn’t seem to be very well liked by coworkers for some reason.

    I don’t see it used in published material very often – the only one I could find in a quick Google right now is an article by Paul DiLascia in MSJ August 1997 (http://www.microsoft.com/MSJ/0897/C0897.aspx):

    CRebarInfo and CRebarBandInfo are programmer-friendly C++ versions of the C structs REBARINFO and REBARBANDINFO, with constructors that initialize the objects to all zeroes before setting the cbSize member appropriately.

    I can’t think of much in the way of drawbacks (except the lack of acceptance). If anyone else can point to something more concrete, I’d appreciate it.

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

Sidebar

Related Questions

No related questions found

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.