[some OT] questions on DLL(Dynamic library)

Windows specific questions.
Post Reply
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

[some OT] questions on DLL(Dynamic library)

Post by oyster »

1. how to convert dll to static lib?
ok, I know this is a strange topic. But I found an very old commercial app http://www.binary-soft.com/dll2lib/dll2lib.htm which said that it can convert DLL file into its equivalent static library

Is there a free one?

2. can we rename the functions in DLL
3. can we strip down a DLL so there is only used function in it

I did not find something useful via google on question 2 and 3, perhaps it because English is not my native language



Thanks
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: [some OT] questions on DLL(Dynamic library)

Post by dodicat »

I have also searched in the past for this (and quite recently for a freepascal project).
Also that site.
I was toying with the download anyway without getting the license, I might try it on my old XP box, but not here on win 10.

You can use an alias name for your function, but you should call the dll with the given name.
declare function myname alias "propername"(...) as something.
If you use a dll and only call one function, you only get one function.
You can see by the size of your .exe, it will remain smaller the less number of functions you use.
If you load an equivalent static you can expect a big .exe, unless your static is a freebasic lib (or other libs perhaps) where functions are marked private in your lib code.
That's my take anyway, others will probably have extra information.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: [some OT] questions on DLL(Dynamic library)

Post by jj2007 »

There is a DLL to LIB thread at Masm32.

Note that many "static" libraries just contain links to DLLs. And if those DLLs are not present on your system, your code will build fine but you will get a runtime error. At that point, why not load the DLLs explicitly? The effect is the same, and your exes are a few bytes shorter.
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Re: [some OT] questions on DLL(Dynamic library)

Post by marpon »

Some year ago i've also tried to convert dll to static lib on an attempt to provide unly 1 executable file not with dll(s) around, with the risk of not using the right version, missing dll etc...
but dll2lib was not working well, so i've changed direction
i've embedded all the dlls i needed into my executable and was able to use them from memory. It is a fairly good work-arround.
no need to have sources...

I've recently made static libs from the result of that test using the o.files (compiled from c in 32 & 64bits) to use in freebasic,
giving the ability of using embedded dll from memory but also launching embedded exe from memory without using temp file to do that

see topicviewtopic.php?f=14&t=27375

what you only need from the dll is the declaration of the export functions you want to use.

Obviously the executable file will increase of the size of what you have embedded.
limitation : No possility to strip what you don't use in the embedded files.
marpon
Posts: 342
Joined: Dec 28, 2012 13:31
Location: Paris - France

Dll to static lib work-arround

Post by marpon »

To continue the subject dll2lib

here are the elements to make tests under 32 or 64 bits

2 dlls as example to use (any else can be used)
calendrier.dll for 32
my_dll64.dll for 64

2 needed static libs, i've coded in c to manage dll from memory, (difficult to translate to fb)
libMemDll_32.a
libMemDll_64.a

2 freebasic code to generate the static libs as dll2lib
dll2lib_test_32.bas will include calendrier.dll
dll2lib_test_64.bas will include my_dll64.dll

2 freebasic code to test these 'static lib from dll'
test_calendrier_lib.bas
test_my_dll64_lib.bas

can be used as template for any dll

the only information you need is the declaration for each exported function/sub you want to use.

As said previously not possible to strip the dll, so you will increase the exe size of the full dll size.

to simplify, all the stuff is on the zip file : test_dll_to_lib.zip
here https://github.com/marpon/mem_exe_dll

interrested on your tests, remarks...
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: [some OT] questions on DLL(Dynamic library)

Post by oyster »

Aha, a smart solution. Thanks
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: [some OT] questions on DLL(Dynamic library)

Post by oyster »

@jj2007
I guess you are the author of MasmBasic. The latest one I download is reported that there is a virus in setup.exe by Avira
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: [some OT] questions on DLL(Dynamic library)

Post by jj2007 »

oyster wrote:@jj2007
I guess you are the author of MasmBasic. The latest one I download is reported that there is a virus in setup.exe by Avira
Thanks for the feedback. It's a false positive, of course, and guess what, we even have a dedicated sub-forum AV Software sh*t list for Avira & friends ;-)

The problem is that most AV software use "heuristics" to guess the malignity of an executable. Hand-optimised assembly code doesn't look like the typical output of Gcc or Visual Crap, and therefore it gets flagged as suspicious. No problem for a hobby coder like me, but it doesn't look so good if you want to sell your executables to an industry client. So you better stick to FreeBasic ;-)
Btw to build my examples, the Masm32 SDK is needed, too.
Post Reply