July 13, 2024, 07:09:23 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Dll2lib

Started by sapero, January 10, 2007, 05:27:07 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

January 10, 2007, 05:27:07 AM Last Edit: February 07, 2007, 05:09:04 AM by sapero
Here it is! A tool to convert simple dll's into static library.
This is the first version, so all here is simple: the user interface has all controls on one page, you are able to access only named exports, and the dll is notified only with process attach/detach.
TLS initialization is not yet supported, module functions will always fail (GetModuleHandle...).
The dll is loaded to memory not as dll, but as code+data (using the MemoryModule loader with small modifications to operate on HMODULE instead MEMORYMODULE*)

Note: every converted dll you must manually initialize and deinitialize by single call to the loader. Every converted dll has its own (un)loader.
You can find a example usage for dx3d9r.dll with landscape.src modification.

Have fun! ;D



edit: version 2.0.0.2 supports names up to 16320 characters

srvaldez


Steven Picard

Once again you have proven how amazing your programming skills are!

ExMember001

looks like a great tool ;)
will give this a go as soon as i have time !

Shannara

sapero -> check pm please.
Love is staying up all night with a sick child, or a healthy adult.

J B Wood (Zumwalt)

Doesn't work on rakknet.dll, get ahold of that and try it with your application, problem is, there names are VERY LONG, and you have a character limit for length of name of the exported items.

sapero

February 07, 2007, 05:00:51 AM #6 Last Edit: February 07, 2007, 05:15:52 AM by sapero
I've uploaded second version that supports names up to 16320 characters (previous limit was 260). I do not belive this is not enough ;)
The raknet has been converted ok,and the simple main() with loader only ran successfully.

// todo: undecorate names

J B Wood (Zumwalt)


Barney

I bow to Sapero's mastery. Fantastic work! Thank you for sharing it with us, lesser programming mortals.

Barney

pistol350

Great !
Sapero You are the man as usual
That's a great program.
I'd be glad to see an Ebasic version. ;)
Regards,

Peter B.

Ionic Wind Support Team

The created library should work fine with Emergence.
Ionic Wind Support Team

sapero

i've created a template for the (GUI) second edition. It uses tabbed property sheet, and looks better than the first version, i think so :D
The resource script was created using ResEd from Shantanu site.
What do you think? It may be not correctly categorized, so please reply with any suggestions.

Haim

Looks very nice.
BTW,
I looked at the dialog editor of ResEd and it looks very appealing.
How do you get the data from the dialog editor?
(controls placement and their various styles and Exstyles?)

Haim

sapero

February 21, 2007, 07:39:17 AM #13 Last Edit: February 21, 2007, 07:56:01 AM by sapero
The ResEd was created for MASM, but here is a Visual Studio version.
In options menu select "C defines" as output format to easier use the script with Aurora.

Secundo: I've found a bug in MemoryModule module. Sections with IMAGE_SCN_MEM_DISCARDABLE flag can be released after calling the dll entry point.
Some packed dll's (like bass) are calculating crc32, and probably my small modification causes MemoryLoadLibrary to fail (i'm saving MEMORYMODULE pointer in dos stub).
I'll look into it, and add a option to disable releasing of discardable sections.

Haim


LarryMc

April 05, 2007, 04:04:19 PM #15 Last Edit: April 05, 2007, 06:07:32 PM by Larry McCaughn
sapero
Here comes a question to display my ignorance.

What's the difference between using your utility and the make lib feature of the IDE.

Why would I want to use your program?

Again, my ignorance.

EDIT:
Okay, let's see if I'm right.
The lib made in the IDE just gives locations of functions in the DLL so you have to send people the dll with your exe.

Your program creates a static lib that loads the functions into your compiled exe so that you don't have to send a dll with your exe.


The price  that is paid is that you have to call "load" and "unload" functions to get the lib functions to work.

How close did I get?

If I'm correct then here's my next question.

If I want to create some wrappers for the functions in the first dll I do the following:
1) use your program to create a static lib of the 1st dll
2) write my wrapper functions including "open" and "close" fucntions to call the "load" and "unload" for the static lib.
3) compile my wrapper module as a dll
4) use your program to create a static lib of my dll along with the "load" and "unload" for it.
5) write my application:
   If 1st calls the "load" for my wrappers
   Then calls the "open" function in my wrappers to call the "load" for the 1st dll functions.

6) at the end of my application:
  call the "close" function in my wrappers to call the "unload" for the 1st dll functions.
  call the "unload" for my wrappers

Can you "nest" them like that.

LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

April 06, 2007, 07:15:57 AM #16 Last Edit: April 06, 2007, 07:21:08 AM by sapero
The ansver for first question:
QuoteDLL to Lib is a magical tool which can convert a DLL file into its equivalent static library file. After that, you can replace the original DLL with the static library file, rebuild your application, and distribute it without the DLL! The most exciting thing is that the conversion process DOES NOT require any source codes of the DLL! All works are done from binary to binary. DLL to Lib will rebuild programming interface identical to the functions exported by the DLL and reconstruct the necessary symbol tables, string tables and reference tables from the DLL to make a valid static library for you! Incredible?
Yes, you can nest it as well. Here is a working sample:
first dll:// dll 1

export GetOnePlusNine;

sub GetOnePlusNine(),int
{
return 1+9;
}
// compile as GetOnePlusNine.dll and convert it to static library GetOnePlusNine_m.lib

second dll that loads the first dll:// dll 2 - uses GetOnePlusNine_m.lib to wrap GetOnePlusNine()

export GetOnePlusNine_wrapped;

#use "GetOnePlusNine_m.lib" // link to static library you created from GetOnePlusNine.dll
#use "zlib.lib" // use static library

// the function we want to wrap
declare import, GetOnePlusNine(),int;

// functions to load and decompress the first dll
extern int __LoadGetOnePlusNine_dll();
extern void __UnloadGetOnePlusNine_dll();

sub GetOnePlusNine_wrapped(),int
{
__LoadGetOnePlusNine_dll();
int result = GetOnePlusNine();
__UnloadGetOnePlusNine_dll();
return result;
}
// compile as GetOnePlusNine_wrapped.dll and convert it to static library GetOnePlusNine_wrapped_m.lib

the main program:// exe main
#use "GetOnePlusNine_wrapped_m.lib"
#use "zlib.lib"
extern int __LoadGetOnePlusNine_wrapped_dll();
extern void __UnloadGetOnePlusNine_wrapped_dll();

declare import,GetOnePlusNine_wrapped(),int;

sub main(),int
{
__LoadGetOnePlusNine_wrapped_dll();

MessageBox(0, str$(GetOnePlusNine_wrapped()), "");

__UnloadGetOnePlusNine_wrapped_dll();
return 0;
}

When the exe starts, it loads the wrapped (second) dll and calls a function, where another dll is loaded (the first one) to return some value.

LarryMc

Thanks a million sapero.

You're the man as usual. ;D
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

Yeah!!
Very interesting.
This helps understanding better how it all works!!
Thanks Sapero  ;)
Regards,

Peter B.

LarryMc

Sapero
I'm using EBasic instead of Aurora and ran into a little problem.

I coverted your example above to EBasic.

Made the first dll and converted it to lib

Tried to compile the second and it won't compile.
It's not liking stricmp in crtdll.lib.
I looked at the 2 crtdll.libs (1 in Ebasic\libs and other in Aurora\libs.

They are not the same.

Got any idea how I can fix it?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

pistol350

I was going to mention that problem  ;D
I tried to compile the seconde DLL in AURORA but failed too
There may be something wrong in the second DLL code  ???

here is what i got
Compiling...
GetOnePlusNine_wrapped.src
No Errors
Generating Exports

Linking...
Aurora Linker v1.0 Copyright ÂÃ,©2005,2006 Ionic Wind Software
Unresolved external __LoadGetOnePlusNine_dll
Error: Unresolved extern __LoadGetOnePlusNine_dll
Error: Unresolved extern __UnloadGetOnePlusNine_dll
Error(s) in linking C:\Program Files\Aurora\examples\dll to lib example\GetOnePlusNine_wrapped.dll

Cheers!
Regards,

Peter B.

LarryMc

In EBasic
If I make dll's with EBasic crtdll.lib then there is a problem with crtdll\stricmp

If I substitute Aurora crtdll.lib then there is a problem with sprintf

Any ideas how to fix?
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

McCaughn, I remember this from IB :)
Open up your LIBS folder, find crtdll.lib and create a backup or rename it.
Run the EB GUI and from menu select Tools->Create import library. Find crtdll.dll and click ok, then ansver YES for "replace existing library" prompt.
Return to LIBS folder and rename the new crtdll.lib to _crtdll.lib, then restore the original crtdll.lib.
Now append a $use "_crtdll.lib" so it should compile now.

pistol350, in your libs folder should be the new lib file with embedded dll, try with #use "name.lib".
Optionally the lib file can be located inside your project directory, but should be added to project (menu->project->insert library).

LarryMc

I wouldn't have dreamed of that in a hundred years.

Thanks
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Ionic Wind Support Team

And there is a reason they are different.  When I was creating IBasic Pro I wanted to be able to use static libraries created with VC++ 5.0 which prepends an underscore to all C library functions.  So I made a special version of crtdll.lib that would link against VC libs.  In order to make Emergence compatible with IBasic source code I used the same import library.

In Aurora that was no longer a priority as it already has OOP, and a more robust object set,and better COM handling, etc, etc.  So the stock crtdll.lib which contains no prepended underscores was used.  In other words I had no need to link to static libs created with VC++

Paul.
Ionic Wind Support Team