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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:52:04+00:00 2026-06-07T19:52:04+00:00

To be tidy, I want to #undef everything defined in windows.h . E.G: namespace

  • 0

To be tidy, I want to #undef everything defined in windows.h.

E.G:

namespace os_stuff
{
    #include <windows.h>

    // ARGH! Macros everywhere!

    // at least I can keep the rest of the API in here
}

// include a bunch of files here that use the Windows API through os_stuff

namespace os_stuff
{
    #include <unwindows.h> // <- #undefs all that was #defined in windows.h
}

// All clean, as though windows.h was never here. Though os_stuff, used nowhere else,
// still has all of the API declarations in it (which is OK).
  • 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-06-07T19:52:05+00:00Added an answer on June 7, 2026 at 7:52 pm

    Rather than undefing everything, avoid defining them in the first place. You can do this by explicitly passing the first part of your module (as a separate source file) through the preprocessor and including the preprocessor output, rather than the original source code, in your module’s main source file.

    I tried this out using Visual Studio 2010. For my trial, I created three source files. This is headers.cpp, analogous to the first part of your sample code:

    namespace os_stuff
    {
    #undef _MSC_EXTENSIONS
    #define _WIN32_WINNT 0x0601
    #include <windows.h>
    }
    
    #include "xyzzy.h"
    

    The #undef _MSC_EXTENSIONS is to prevent the inclusion of sourceannotations.h, because that file generates errors when included from inside a namespace.

    This is xyzzy.h, to demonstrate “include a bunch of files here” from your sample code:

    os_stuff::DWORD myFunction(os_stuff::HANDLE h);
    

    And this is test.cpp, analogous to the “all clean” part of your sample code:

    #include "headers.h"
    
    int main(int argc, char ** argv)
    {
      os_stuff::DWORD UNALIGNED;
      os_stuff::HANDLE h = 0;
      UNALIGNED = myFunction(h);
      return UNALIGNED;
    }
    

    Note that we’re using UNALIGNED as a variable name, not because it makes sense, but just as an example of something that won’t work if you’ve included windows.h directly (because it expands to the __unaligned keyword).

    From a Visual Studio 2010 command line, create headers.h like this:

    cl /P headers.cpp /Fiheaders.h
    

    The /P option is documented here.

    You can then compile test.cpp in the usual way:

    cl test.cpp
    

    (Obviously in this case the program won’t link because we haven’t defined myFunction, but it compiles perfectly happily.)

    With a bit of fiddling around it shouldn’t be too hard to automate the building of headers.h rather than doing it from the command line.

    In some C++ compilers the preprocessor is actually a separate executable (this was the traditional model) but if not there should still be an option to just run the preprocessor without invoking the compiler.

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

Sidebar

Related Questions

I want to keep my templates tidy and nicely intented but would like to
I want to parse HTML (you can assume as a XML, converted via Tidy)
I'm using SQLalchemy for a Python project, and I want to have a tidy
I have HTML tidy extension on my home computer using PHP 5.2.11 (Windows -
When using the PHP Tidy Library (More Specifically, The tidy_repair_string function) I keep getting
How can we write html tidy coding only for inserting closing tag in the
I want to extract particular part of HTML using tidy in php. the html
I'm trying to tidy all my css code on my site, I want to
I am trying to tidy up my code so that I can easily reuse
I am trying to keep my code tidy and move most of the functionality

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.