Should I export DllMain() function?

This is a discussion on Should I export DllMain() function? within the Windows Programming forums, part of the Platform Specific Boards category; I created a dll file, and I wanted the resources it uses to be initialized when the dll gets loaded, ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    34

    Should I export DllMain() function?

    I created a dll file, and I wanted the resources it uses to be initialized when the dll gets loaded, so I wanted to include DllMain function in the dll file.

    Code:
    // DllMain.cpp
    #include "windows.h"
    
    int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*pReserved*/)
    {
        ...Do Initialization...
    }
    Do I need to compile DllMain.cpp file along with the sources for the dll
    file for the above DllMain() function to be called? or can I 1) compile the dllmain.cpp file into a .lib library file 2) statically link the library to the dll during a link-time?

    Also, do I need to export the DllMain function (using the.def file for the dll file)? Thanks!

  2. #2
    C++11 User Tux0r's Avatar
    Join Date
    Nov 2008
    Location
    Sweden
    Posts
    135
    I believe you ought to have posted here Windows Programming

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,457
    Right, and moved.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    DllMain needs to be part of your dll source (compiled as part of the dll and part of the dll binary) and no, it does not need to be exported.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    DllMain is just like WinMain in the sense that it is required (or optional in the case of DllMain) simply for somewhere for the CRT to pass control to after it is has finished initializing. It is internal to the module.

    The PE format (which all Win32/64? EXEs and DLLs are in) specifies a single entry point address at which execution of the module begins; for C/C++ programs this usually the CRT routine that initializes, calls your WinMain/DllMain, then trashes any resources the CRT used.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  4. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21