Converting a Windows Dll to .lib for C++ Visual Studio 2008

此生再无相见时 提交于 2019-12-02 23:28:17

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.

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

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

(See second link for an example).

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.

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.

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.

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'.

Open source edll has its own internal COFF loader. edll is written for quite different purposes, but since it has independent COFF loader within, maybe it's possible to incorporate your .dll into binary stream or resource inside your .exe, then in run-time use edll's COFF loader to load built-in dll.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!