locked
Important: Undecorated DLL import RRS feed

  • Question

  • Hello, I have a problem since 7 days and asked in several boards. Nobody knew the answer. I have a DLL created with Delphi which exports STDCALL functions with undecorated names (Pascal-Style). I do not want to decorate the names and I do not want to dynamically link the DLL.

    I have created a DEF file which looks like this:

    LIBRARY   statmondll32
    EXPORTS
    getVersionNumberA@0=getVersionNumberA

    Then I compiled it with lib.exe

    lib.exe /def:statmondll32.def /out:statmondll32.lib

    When I view the LIB in dumpbin, I notice that the name is not undecorated (neither my alias is accepted):


      Symbol name  : _getVersionNumberA@0
      Type         : code
      Name type    : no prefix
      Hint         : 0
      Name         : getVersionNumberA@0

    The name type is "no prefix". But when I look at WinAPI-LIBs (which are also STDCALL _and_ undecorated), they have "undecorate" as "name type".

    I have found a workaround with an hexeditor, but it is very nasty in my opinion: I search the last occurence of "_getVersionNumberA@0" and then I go left 2 bytes. I change the byte 0x08 ("no prefix") into 0x0C ("undecorate").

    After this, the dumpbin looks like this:

      Symbol name  : _getVersionNumberA@0
      Type         : code
      Name type    : undecorate
      Hint         : 0
      Name         : getVersionNumberA

    My important question is, how can I tell lib.exe to undecorate the function names without using a hex-editor?

    My product is MS VC++ 2010 Ultimate (student edition MSDNAA), Lib.exe version 10.00.30319.01.

    Saturday, September 3, 2011 6:10 AM

Answers

  • Can you show us how the functions are declared in the header your C++ application is importing in order to use the DLL?  I'm looking for the following aspects:

    extern

    extern "C"

    stdcall

    and of course the function declaration itself.


    Answering policy: see profile.
    • Marked as answer by Rob Pan Friday, September 9, 2011 8:07 AM
    Saturday, September 3, 2011 7:01 PM

All replies


  • Take a look at the section named Standard Call or PASCAL Functions in Creating Dynamic Link Libraries (non-Microsoft site); it has an interesting idea, which is to repeat the symbol thus:

    LIBRARY   statmondll32
    EXPORTS
    getVersionNumberA@0
    getVersionNumberA=getVersionNumberA@0
    

    I'm not sure it will work, but it's worth a try IMO.


    Answering policy: see profile.
    Saturday, September 3, 2011 1:09 PM
  • Thank you for your comment.

    Alas, it does not work. It will create 2 different symbols which are both not working

    Symbol #1:

      Symbol name  : _getVersionNumberA
      Type         : code
      Name type    : no prefix
      Hint         : 0
      Name         : getVersionNumberA

    --> "Symbol name" is wrong. "Name" is ok.

    Symbol #2:

      Symbol name  : _getVersionNumberA@0
      Type         : code
      Name type    : no prefix
      Hint         : 1
      Name         : getVersionNumberA@0

    --> "Name" is wrong. "Symbol name" is ok.

    Thus, C++ finds symbol #2 and tries to access "getVersionNumberA@0" in the DLL, which does not exist.

    The information on that website related to "dlltool" with the "-k" (--kill-at) option. I am not sure where to find dlltool and if its LIB files are compatible with VC++ (I doubt it since e.g. Delphi's LIB files are also incompatible with VC++).

    Saturday, September 3, 2011 5:21 PM
  • Can you show us how the functions are declared in the header your C++ application is importing in order to use the DLL?  I'm looking for the following aspects:

    extern

    extern "C"

    stdcall

    and of course the function declaration itself.


    Answering policy: see profile.
    • Marked as answer by Rob Pan Friday, September 9, 2011 8:07 AM
    Saturday, September 3, 2011 7:01 PM
  • I covered "undecorate" in my blog:

    http://qualapps.blogspot.com/2007/08/how-to-create-32-bit-import-libraries.html

    There's a lot of undocumented behavior that makes all of this work.


    Jim Beveridge

    Sunday, February 3, 2013 5:32 AM