how can i convert .dll in .lib and .lib in .dll ?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 772
Joined: Fri Dec 04, 2015 9:26 pm

how can i convert .dll in .lib and .lib in .dll ?

Post by skinkairewalker »

hi everyone !
somenone can help me ?

how can i convert .dll in .lib and .lib in .dll ?
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by jack »

hello
I know how to convert a mingw lib to a dll but have not done so using VS or PellesC which is probably what you want, as for converting a dll to a lib I don't know how one would go about it, there use to be a commercial software that claimed to do so but the price was like $999.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by Lunasole »

There are 2 kinds of .lib (statical library on windows):
- first contains all the functions and their code, program used this lib is fully independent.
- second contains only function descriptions from some .dll file. code is located in dll and program uses this lib cannot start without required dll.

If you have .dll and don't have it's source code, you can only build second kind of .lib. That can be done using POLIB.EXE (comes with Purebasic), or more handy "Lib2PB Import" tool (search in google or here on forum).

If you have full sources (usually C or C++), you can compile both types of lib and dll from it, which sometime requires code changes (generally for dlls you need to mark export table) and will be painful for first times.
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by jack »

if you have a static lib (not an import lib) you should be able to extract the objects and then use link to create a dll, something like link /DLL /IMPLIB:mylib.lib /OUT:mylib.dll *.obj
I just tried to extract the objects from a static lib using ar and it worked ok, (ar x yourlib.lib)
[edit] just remembered that polib has an explode option to extract objects from static lib
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by sys64802 »

jack wrote:there use to be a commercial software that claimed to do so but the price was like $999.
This can be tried, says it's fully working but time limited until registered. 32 bit only.

http://www.binary-soft.com/dll2lib/dll2lib.htm
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by jack »

I see he lowered the price, $100 is not so bad, but with 32-bit only it's usefulness is limited.
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by Keya »

another option instead of dll-to-lib (i think currently PB code only exists for Windows though):
if you just want the effect of having the .dll inside your exe (no separate dll file on disk, good if you just want a single executable to distribute without dependencies!) you could use one of those slick "load dll from memory" functions :) [Example]
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by sys64802 »

@keya

uhm, that one looks a little too simple and doesn't support some things... I don't think it can really work, or maybe can work only in some cases. Did you try it and worked ?

The one in C from the library is certainly a lot better even if probably still not perfect. But it's good enough.
http://www.purebasic.fr/english/viewtop ... 99#p323299
User avatar
Keya
Addict
Addict
Posts: 1890
Joined: Thu Jun 04, 2015 7:10 am

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by Keya »

yes it works well. I havent tried the one you linked to but i noticed it comes with just the one .lib file, wouldnt it need two to support both x86 and x64? im not sure
sys64802
Enthusiast
Enthusiast
Posts: 105
Joined: Sat Sep 12, 2015 6:55 pm

Re: how can i convert .dll in .lib and .lib in .dll ?

Post by sys64802 »

That was a older link sorry, at the time I downloaded it from here
http://www.realsource.de/downloads/doc_ ... morymodule

That was the one I was using before writing my own, and it worked well with the dll I tried (just two or three).

That's why I know that one is nice, because I studied its source well (it's very educational) before writing my version which has some differences.

The one you linked in source doesn't work as it is anymore, removing the structures already defined in PB now and removing the unpackmemory() to make it compile (not executed anyway with an unpacked dll) it crashes with the dll I'm testing it with at

Code: Select all

If CallFunctionFast(BaseVirtDll + *NT_HEADERS\OptionalHeader\AddressOfEntryPoint, BaseVirtDll, #DLL_PROCESS_ATTACH, 0)
Same dll with the library above it's working, but I don't have the desire to try to understand why it doesn't with this source :wink:

Maybe you modified it, or maybe the structures are different ? Don't know. Anyway just looking at it it seems to me also it doesn't support function forwarding, and that can be found in many dlls, especially OS dlls.

Anyway the lib above it's both 32 and 64 bits if you are interested.
Post Reply