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

  • SEARCH
  • Home
  • 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 3936514
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:57:25+00:00 2026-05-19T23:57:25+00:00

First of all, I know global variables are evil :) However, there is legit

  • 0

First of all, I know global variables are evil 🙂 However, there is legit case why I need to use one.

I know that there are very strict limitation on what can be executed in DllMain (no LoadLibraries, no COM initialization and so on).

And I know that global variables are initialized just prior DllMain DLL_PROCESS_ATTACH.

Do I have the same limitation while global variable initialization?

I found Microsoft article: http://msdn.microsoft.com/en-us/library/988ye33t
However, it doesn’t have any details related to the limitations.

I saw also another Stackoverflow questions: What happens to global variables declared in a DLL?
Here is snippet from there “There are things that are forbidden to do in the DllMain. Those things are probably forbidden, too, in the constructors.”

However, it looks like commentor isn’t sure whether such limitations are really exist.

I would appreciate any information on this subject.

  • 1 1 Answer
  • 3 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-19T23:57:26+00:00Added an answer on May 19, 2026 at 11:57 pm

    As explained in this answer of mine, the real dll entrypoint (i.e. the real DllMain) is taken by the CRT, that, on DLL_PROCESS_ATTACH, initializes its stuff, calls the constructors of the globals and then call the “fake” DllMain (i.e. what you as a programmer see as DllMain).

    The MSDN documentation calls DllMain the real dll entrypoint, so all the restrictions apply also to the constructors of global objects, since they are called by it.

    This is yet another reason to avoid globals: the code in their constructors is called from DllMain, but this is not evident, so in case of problems coming from doing “forbidden” things in DllMain it may take a lot of time before acknowledging that the offending code is in such constructors.

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

Sidebar

Related Questions

First of all: I do know that there are already many questions and answers
First of all, I know there are a few quite similar questions here on
First of all, I know that UDP is not a reliable protocol but I
Hi there First of all just let me say that I'm new in Python
First of all I know similar questions has been asked here, I've checked but
First of all i don't know whether the title is relevant or not (please
First of all I don't know if this is the right approach. I want
first of all i would like to say i know its probably an easy
First of all sorry for the name of the title, but i dont know
First of all, I apologize for the English, I don't know how to write

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.