Menu

My DllMain function is not called

2005-07-28
2012-09-26
  • Nobody/Anonymous

    Hello,

    I'm at learning how to use dlls and as i make some tries, i noticed that my entry point wasnt called. I added other functions in the dll to test them and they are called without any problem, it's just the DllMain.

    DevCpp 4.9.9.2
    OS : Windows XP Home Version 2002 SP1

    The dll's code : the code that is written by default when starting a new project and selecting "dll".

    The exe's code : a simple console application including dll.h (the dll's header).
    I added the libdll.a to the project.

    The Compile log tells me :
    "Compiler: Default compiler
    Building Makefile: "C:\Documents and Settings\Gilles\Mes documents\c++\mes sources\Makefile.win"
    Executing make...
    make.exe -f "C:\Documents and Settings\Gilles\Mes documents\c++\mes sources\Makefile.win" all
    dllwrap.exe --output-def libdll.def --driver-name c++ --implib libdll.a dllmain.o -L"lib" --no-export-all-symbols --add-stdcall-alias -o dll.dll

    dllwrap.exe: no export definition file provided.
    Creating one, but that may not be what you want

    Execution terminated
    Compilation successful"

    I made some searches on the web but i really dont know what's wrong. Could someone help me ?

    PS : i'm french so dont mind if i wrote some things wrong :o)

    Gilles

     
    • Nobody/Anonymous

      Thanks all for your help and thanks alot to Liviu for his post !

      DllMain should efectively declared as extern "C".

      Merci ;o)

      Gilles

       
    • Nobody/Anonymous

      Salut Gilles,

      tu pourrais l'utilisr comme rfrence:

      http://www.flipcode.com/articles/article_creatingdlls.shtml

      Mike

       
    • Nobody/Anonymous

      Thanks Mike but in this tutorial they uses VC++ and not DevCpp.

      In fact i think the problem comes from :
      "dllwrap.exe: no export definition file provided.
      Creating one, but that may not be what you want ".

      But i dont think how to solve it...

      Is there any default settings that tells the compiler not to export the entry point function or something likek that ?

      PS to Mike : dsol mais j'cris en Anglais pour que tout le monde puisse suivre ;o)

      Gilles

       
    • Nobody/Anonymous

      try to copy paste the contents of the link I provided and compile them, they should work.
      The "no export definition file provided" stuff is always there here too and every dll I compile works flawlessly. I suppose that isn't your problem, I would guess its more likely the way you call the functions from the dll in your main application. You might use the examples from the link as a reference.

      greets,

      Mike

       
    • Nobody/Anonymous

      dllwrap.exe: no export definition file provided.
      Creating one, but that may not be what you want

      This means that a .def file is being generated with the export definitions. Functions that are exported are the ones that have the declaration "__declspec(dllexport)". These will be included in the .def file and are the ones you can call from an external program. Does your DllMain have this declared?

       
    • Nobody/Anonymous

      hmm, i have no problem at all when i try to use import and use an function that i exported in my dll, the problem is tha DllMain function (the entry point of the dll) which its prototype is :

      BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)

      This function should be called when the dll is mapped in the process's address space (for exemple) but it isnt. All code i use to test it is the default dll code from DevCpp with a printf in this function to see wether it's called or not.

       
    • Liviu Nicolescu

      Liviu Nicolescu - 2005-07-29

      When compiling with g++, you should add extern "C" linkage declaration to DllMain, otherwise the name is mangled by the compiler and the entry point is not called.

      Ex:

      ifdef __cplusplus

      extern "C"

      endif

      BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)

      Liviu

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.