Generate lib to link in c from 32 bit dll stdcall functions without decoration

46 Views Asked by At

Generating xxx.lib from xxx.dll with both name and ordinal can be done with a xxx.def generated from xxx.dll's dumpbin results (consider a dll with void foo() and void bar(int)):

dumpbin -exports xxx.dll

Exports

       ordinal    name
             0    foo
             1    bar

Then process this result, and generate the following xxx.def

EXPORTS

    foo    @0
    bar    @1

And then the following to generate the xxx.lib

lib /def:xxx.def

This works with c++ decorated names, but not so intuitive with C functions. C functions have decorations, and it seems lib tool accepts the names as C function names. So the export symbols in the above xxx.lib is in-fact _foo and _bar mapped to foo and bar in the dll.

This works with most 64 bit things, since calling convention is the same, all you need is to declare the function as a normal cdecl c function. In 32 bit, however, the compiler looks for _foo@0 and _bar@4 for stdcall (you cannot specify cdecl in import, since they are fundamentally different), and cannot be satisfied.

Is there a way to still statically load 32 bit dll when you have the header but not source code? (A loader should be possible, but that would mean much more work to do, and that's dynamic)

0

There are 0 best solutions below