Menu

Old school DLL exports

2002-12-15
2012-09-26
  • Nobody/Anonymous

    Still porting my dll. I've finally made it compile, but ... the mangled names are missing a leading underscore (I'm looking at the dll with a hex editor).

    prototypes for exports look like this:
    extern "C" { //doesn't matter much if I leave this out
    __declspec (dllexport) void __stdcall some_function(int blah);
    //more declarations of this type here
    }

    Sample definition:
    __declspec (dllexport) void __stdcall some_function(int blah)
    {
    //yadda yadda
    }

    Which results in the following mangled name:
    some_function@4

    This is almost it, with the exception of the leading underscore. Ie
    _some_function@4

    I've honestly tried, I've used -fleading-underscore as compiler option, but that didn't change a thing (?). Is renaming all functions the only way to get the desired export names?

    I hate to say it, but that would break portability with MSVC *eg*

    Possibly unrelated, but I've also kind of lost my DllMain export ... it's not in the generated DLL, though the function is properly defined.

    Current command line stuff in project options:
    Compiler: -shared -DBUILD_DLL -fleading_underscore
    Linker: --no-export-all-symbols -lopengl32 -lgdi32 "assembly.obj" -s

    As said, compiles without warning, links without warning, generates a proper DLL. It's all about the name mangling and DllMain.

    Sorry if I'm just being dumb, but it's been a busy night and I'm tired, hope you can help me out.
    Puzzled,
    -zeckensack

     
    • Nobody/Anonymous

      Ugh, just forget about DllMain ... I've just noticed that it's also not in the MSVC generated DLL. That has been working fine all the time, and that can only mean one thing:
      I need to learn more about DLLs.

      Sorry
      Grabbing more coffee
      -zeckensack

       
    • Nobody/Anonymous

      Okay, I thing I've found a solution to my underscore problem. It's somewhat messy but here goes, in case anyone's interested:

      //in header

      //check for MSVC
      #ifdef _MSC_VER
      #define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall name parms
      #define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall name parms
      #endif

      //check for GCC/MingW
      #ifdef __GNUC__
      #define DECLARE_EXPORT(name,ret,parms) extern "C" __declspec(dllexport) ret __stdcall _##name parms
      #define IMPLEMENT_EXPORT(name,ret,parms) __declspec(dllexport) ret __stdcall _##name parms
      #endif

      DECLARE_EXPORT(grDrawPoint,void,(const Vertex* point));
      __________________
      //in cpp
      IMPLEMENT_EXPORT(grDrawPoint,void,(const Vertex* point))
      {
         //yadda yadda
      }
      ___________________

      Actually quite simple :-)
      -zeckensack

       
    • Anonymous

      Anonymous - 2002-12-15

      From Dlltool documentation...

      -U
      --add-underscore
      Specifies that when dlltool is creating the exports file it should prepend an underscore to the names of the exported functions.

      RTFM

      Toni

       
      • Nobody/Anonymous

        Huge thanks for the switch! :-)

        Re: RTFM. I would have liked to. Honestly. I've tried the dll_wrap_ docs, which obiously wasn't the right place to look. Binutils still confuse me a bit. Thanks to your intervention I've finally found what I need.

        Grateful anyway,
        -zeckensack

         

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.