views:

2143

answers:

8

I know there is a tool called Dll to lib but the developer is asking $1000. I only need to convert one library, once, so its not easy to justify that price.

I tried IMPLIB32.EXE, but I just get empty .lib files. How can I accomplish this? Perhaps I can write a simple conversion app?

Added1:

The Dll's are typically stdcall not cdecl and written in older C like languages NOT C# or .NET or C++. I now need to call them from C++ apps. An example would be the SQLite.dll or zlib.dll. I do not have access to the .lib files for these dll's.

Added2:

I re-wrote this code for VS2008 http://floodyberry.wordpress.com/2008/09/08/generating-dll-wrappers/ and included the example Dll etc downloadable here: http://www.transferbigfiles.com/Get.aspx?id=7d86fa0b-6ddc-4f6f-8d31-2c20824aae9a This in turn makes a project that creates a Dll. When I try to compile the Dll I get the linker error: AddShow.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x300 Described here: http://list.isis.vanderbilt.edu/pipermail/udm-users/2006-March/000664.html Not sure how to proceed. So close yet so far

Next we move to this method

http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/

Running dumpbin with the argument /exports C:\path\to\AddShow.dll does absolutly nothing After some research

http://msdn.microsoft.com/en-us/library/aa446532.aspx it seems that mspdb71.dll (now mspdb80.dll) is needed from the common/ide folder dumpbin.exe now runs with error:

fatal error LNK1106: invalid file or disk full: cannot seek to 0x6179A These threads suggests the version of dumpbin.exe might be the issue

I have Microsoft (R) COFF/PE Dumper Version 9.00.30729.01

So I tried Microsoft (R) COFF Binary File Dumper Version 5.12.8078 with no success. After much reading I am no closer

http://support.microsoft.com/kb/815645 http://support.microsoft.com/kb/839286 http://markmail.org/message/p5vwzyfyv3bs6z34 http://fixunix.com/programmer/94825-fatal-error-lnk1106-invalid-file-disk-full.html

When I run ProcMon I see the first occurance of queryopen and sqlite3.dll when svchost.exe tries to open it and fails with the error PATH NOT FOUND. the path is C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\SQLITE3.DLL and is correct. If I put it at the root of the C drive then I get NAME NOT FOUND errors:

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\link.exe.Local

C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\dumpbin.exe.Local

from link.exe and dumpbin.exe respectivly. Im using XPSP3 not Vista and this is about the limit of my knowledge of sysinternals. what are these .local files?

(csrss.exe is also not able to find a few manifest files.)

So no success yet, just more mystery

Added 3:

I tried to run dumpbin.exe from its installed location, \Program Files\Microsoft Visual Studio 8\VC\bin, but the OS said it couldn't find mspdb80.dll. I copied mspdb80.dll from \Program Files\Microsoft Visual Studio 8\Common7\IDE to try to get dumpbin.exe to run.

now I get the error: "c1902 program database manager mismatch please check your installation"

If I remove mspdb80.dll from \Program Files\Microsoft Visual Studio 8\VC\bin the error goes away! but I can't run dumpbin.exe.

Added 4:

I was finally able to get dumpbin to run by copying the following files to a folder:

dumpbin.exe link.exe lib.exe mspdb80.dll

I did get the error:

fatal error LNK1248: image size (FFFFFXXX) exceeds maximum allowable size (80000000)

once, but replacing the dll fixed that. Presumably it got corrupted?

I then moved onto the next step in the instructions: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/ http://support.microsoft.com/kb/131313 and got the error: warning lnk4017 statement not supported for the target platform ignored This turns out to be because I specified the .dll instead of the .def file.

The resulting .Lib and .exp files are then added to the VS2008 project and compile and run. The debugger then reported an error: Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call...

As mentioned here http://stackoverflow.com/questions/1465207/run-time-check-failure-0-the-value-of-esp-was-not-properly-saved-across-a-fun this is because I used stdcall in my dll and declared __cdecl in my app.

extern "C" { // put Dll C function prototypes here
 int __cdecl AddTwoNum(int n, double f); // __stdcall
}

So changing this to __stdcall should fix it you would think.. but alas no.

now I get a linking error: error LNK2001: unresolved external symbol _AddTwoNum@12

This is a decorated function name for some reason. Why?

Added n:

Well this turned out to be because the .lib file was made using a dll that with STDCALL functions. STDCALL requiers the caller to clean up the stack so the number of bytes of the arguments is appended to the function name with an @ sign. IN this case I had three 4Byte iintegers for a total of 12 bytes.

Once I remade the .lib file from a dll created with the CDECL calling convention then all was good.

A: 

This is supposedly a free tool that makes the conversion. I'm not sure if it's "free" as in "limited trial version" or not, the information is not very clear. If you've already tested this, edit your question and I'll delete this answer.

unwind
this is the $999 tool (now in ver 3.0, but thank you anyway.
Mike Trader
Well you were right. I offered him $100 and he agreed. I prefer to have my own solution tho.
Mike Trader
@Mike Trader - Don't you mean I was right about asking for the discount? :)
Dana Holt
+3  A: 

I am assuming you want to call some function/methods in a dll in C/C++ without having access to the lib file to link with it.

If you know the signatures of the functions you require, you can:

  • create your own stub version of the dll
  • create a dll project, with the same name as the dll you want to use
  • add stub implementations of the functions you want to call
  • the signatures are very important use depends.exe or dumpbin.exe to check they match.
  • then write/build your program to link to the stub dll
  • to run the program replace the stub dll with the real one
iain
you assume correct. I usually have the .h header file so I do know the signatures. The steps you detail are all new to me. If you could detail them or link to a demo I would be very grateful.
Mike Trader
Basically, this comes down to creating a new DLL project that will generate the same import lib as the one you're missing.
RaphaelSP
Right. Its just a case of navigating the difficult waters to get there
Mike Trader
+3  A: 

You could also go the dynamic way, using LoadLibrary() and GetProcAddress().

(See second link for an example).

RaphaelSP
Thank you. Yes thats always a good way. That will work, but the purpose of this question is to include the library in a VS2008 project without spening $1000
Mike Trader
A: 

If you contact the developer of the Dll to lib tool they might be willing to give you a discount.

I've been in these situations before (where I needed an expensive tool just one time), and sometimes I have had success in getting a large discount.

It never hurts to try.

Good luck.

Dana Holt
You are right. I did. He accepted $100 for the product, but after doing this much work, I am going to roll my own.
Mike Trader
+1  A: 

In cases like zlib or sqlite you can download the source directly and compile your own lib file. In fact, I just did this the other day for zlib, I downloaded the source from www.zlib.net (direct zlib 1.2.3 download) opened the provided visual studio project file and compiled both a debug and release version of the lib. I haven't tried sqlite but seeing that they have the sources, it shouldn't be difficult to do.

If it's a proprietary dll, you could try asking the original developer or company for a lib file, or write your own stub dll that iain suggested or go the dynamic route that RaphaelSP.

If they are exported in C (no C++ name mangling) I would go the dynamic route myself.

Joshua
Yes. The Dll's I wish to convert do NOT have .def or .lib files available ONLY the header.
Mike Trader
+2  A: 

I can't seem to comment on his answer (I need more reputation?), but you can try using my .dll wrapper generator to create the stub .dll iain suggested.

floodyberry
you've got mail
Mike Trader
Thank you for this code. I get stumped at the finish line. see above
Mike Trader
I found: http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/b307bf26-2441-438f-960d-6b54db83fd6dAre you linking against the .dll instead of the .lib?
floodyberry
Aaah. That was the crucial piece I was missing. Now it works! Many thx for the code.
Mike Trader
Just so I understand the concept, the new dll project is infact a wrapper of the original dll that simply loads it dynamically using LoadLibrary() and GetProcAddress() is that right?
Mike Trader
Yes. It's designed so you can easily generate wrapper .dlls to intercept/modify calls when you don't have access to the source. e.g. A ws2_32.dll wrapper to modify network calls like if you wanted to do manual throttling of an app and such.
floodyberry
Ah ok. While this may work, it is not really Static loading. The wrapper DLL is statically loaded, but the actual dll im calling is not, which is the thrust of this question. Thx tho.
Mike Trader
Oh, the point of linking against the wrapper is just to get the it to statically link to the DLL. Once your app is built, you just replace the wrapper DLL with the original DLL and it should work fine (assuming it worked with the wrapper).
floodyberry
A: 

I found this example rather quickly: http://www.coderetard.com/2009/01/21/generate-a-lib-from-a-dll-with-visual-studio/

Luke
Thank you. I spent a few hours working with dumpbin.exe and had no luck. my notes are above
Mike Trader
A: 

I have had success in getting a lib from DLL using details in http://wyw.dcweb.cn/dllfaq.htm. Your mileage might vary. I have used this to get a lib from python DLL to build some python extensions that are written in 'C'.

hackworks