Linking to DLL without LIB and call it's function of stdcall

This is a discussion on Linking to DLL without LIB and call it's function of stdcall within the Windows Programming forums, part of the Platform Specific Boards category; Hi, recently I learning about creating and using DLLs. I learned that it's very common to declare function as __stdcall. ...

  1. #1
    Beginner leiming's Avatar
    Join Date
    Jan 2008
    Location
    Fujian, China
    Posts
    25

    Linking to DLL without LIB and call it's function of stdcall

    Hi,
    recently I learning about creating and using DLLs.
    I learned that it's very common to declare function as __stdcall.
    but then I found a problem that it's hard to link with DLL without lib.
    because compiler would like to look for the function name with "@nn" at the end while the lib made from def file not.
    so I made a tool to solve the problem.
    hoping it helps.

    download:
    http://dl.dropbox.com/u/5740653/dllstdfix_20100414.7z

    how to use

    when got a DLL file with stdcall functions inside, run this tool:
    1. using OpenWatcom C: dllstdfix w xx.dll
    2. using Microsoft Visual C++: dllstdfix v xx.dll
    3. using MinGW GNU C: dllstdfix g xx.dll
    4. using Borland C Compile: any of above

    to get three files:
    xx.dll.def
    xx.dll.asm
    xx.dll.inc

    then compile xx.dll.asm with YASM or NASM, got xx.dll.obj
    nasm -f win32 xx.dll.asm
    (if you use borland C Compile, it's not necessary)

    then make the import library
    1. when using MinGW GNU C Compiler:
    dlltool -l xx.a -d xx.dll.def -D xx.dll
    ar rs xx.a xx.dll.obj

    2. when using Microsoft Visual C++:
    lib /def:xx.def /out:xx.tmp.lib
    lib xx.lib xx.tmp.lib xx.dll.obj
    del xx.tmp.lib

    3. when using OpenWatcom C:
    lib386 /def:xx.def /out:xx.tmp.lib
    lib386 xx.lib xx.tmp.lib xx.dll.obj
    del xx.tmp.lib

    4. when using Borland C Compiler
    implib -f xx.lib xx.dll.def
    (yes, the obj file is not necessary)


    at last, you can link your program with the library. without the problem of
    "error LNK2019: unresolved external symbol"
    "undefined reference to"

    any advice is welcomed.

    the tool uses udis86 as disassemble engine.
    (to know how many bytes is poped when return)

    Regards,
    LeiMing
    Last edited by leiming; 04-14-2010 at 02:42 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    And why exactly would I want to do it instead of linking with the lib-file which comes with the dll?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Beginner leiming's Avatar
    Join Date
    Jan 2008
    Location
    Fujian, China
    Posts
    25
    Quote Originally Posted by vart View Post
    And why exactly would I want to do it instead of linking with the lib-file which comes with the dll?
    what I want to solve is the situation that the dll comes without lib or not usable with the compiler I'm using

    http://dl.dropbox.com/u/5740653/dllstdfix_20100415.7z

    bug fixed.

    I wonder if I got a right way to solve the problem...
    Last edited by leiming; 04-15-2010 at 03:27 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ compiler as a lib function?
    By mustermeister in forum C++ Programming
    Replies: 5
    Last Post: 03-21-2010, 10:36 AM
  2. Using a dll to call a dialog in OnInitDialog of another.
    By mhandlon in forum Windows Programming
    Replies: 1
    Last Post: 03-22-2006, 10:10 AM
  3. problem about static Lib and function pointer
    By wu7up in forum C Programming
    Replies: 3
    Last Post: 02-24-2003, 08:34 AM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM
  5. Function Call From DLL
    By (TNT) in forum Windows Programming
    Replies: 5
    Last Post: 05-05-2002, 09:33 PM

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