PlanetSquires Forums

Support Forums => General Board => Topic started by: Paul Squires on June 02, 2015, 08:07:25 PM

Title: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 02, 2015, 08:07:25 PM
Inspired by a utility that I saw that Marc Pons wrote last year, I decided to create a little program that reads a DLL and creates the corresponding FreeBASIC import library. In FB 32bit, those are the libraries that you will find in the \lib\win32 folder and have a format such as lib*.dll.a

MakeLIB takes as input a standard Windows DLL. It will create and shell to a batch file that invokes PEXPORTS.exe to create the export definitions (DEF) file and finally DLLTOOL.exe to create the *.a file. Simple.

You will need at least FireFly for FreeBASIC 3.74 (June 2, 2015) in order to compile the source code.

MakeLIB (32 bit exe and source files)   http://www.planetsquires.com/files/MakeLIB.rar


Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Marc Pons on June 03, 2015, 05:23:46 AM
Hi Paul

The attachments do not work!
Please Check.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 03, 2015, 09:18:20 AM
Weird. There were already 10 or 15 downloads of the attachments but when I tried to download I kept getting a 404 file not found error. I repackaged the files into zip format rather than rar format and re-attached them to the original post. Hopefully it works okay now. I was able to download them.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Richard Marchessault on June 04, 2015, 11:50:02 AM
I cannot download either of the zipped files. When I click on the link I get an error message that the file was not found.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 04, 2015, 01:23:36 PM
I don't know why this is happening. I deleted the attachments again and will upload them later. The forum software reports those two files as being in the database but missing for the folder. I will upload them to a folder on the PlanetSquires and then people can download it directly rather than having to go though the attachment process.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 04, 2015, 04:54:56 PM
Okay, I have updated the original post to include download links rather than attachments.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Rolf Brandt on June 09, 2015, 06:40:24 AM
Hi Paul,

the links seem not to work either.

Rolf
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 09, 2015, 09:15:39 AM
Hi Rolf - I have re-uploaded the two files again. Something is going on with the forum attachment system and/or my file save folder on the server. Very strange.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Rolf Brandt on June 09, 2015, 09:34:03 AM
Thanks Paul,

now it worked.

I am very happy to see you are continuing further with FireFly. I am playing around with FreeBasic since yesterday. Looks quite promising. And the learning curve is not very steep.

The future is looking a little brighter again. I am sure many in the forum will be very happy about this.

Best wishes
Rolf
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Marc Pons on June 11, 2015, 02:12:45 PM
Hi Paul

I've just tested your Makelib utility , I've some comments

first it fails when trying to interface the user32.dll ( I always test whith this dll because its big and tricky)
it seems, its PEXPORTS.exe problem why ?

second point PEXPORTS produce DEF file without decoration part (mangled) even that decoration exists, the declare function must be inclosed by
Extern "windows-ms" Lib "xxx"  / End Extern       to be able to link
the normal "official" lib interfaces are most of them mangled and the .bi files propose
 Extern "windows" Lib "xxx"   / End Extern

i've also reactived my first version , and post my reduced/simplified one at :
http://www.freebasic.net/forum/viewtopic.php?f=8&t=22882&p=208428#p208428 (http://www.freebasic.net/forum/viewtopic.php?f=8&t=22882&p=208428#p208428)

in case, some here interested...
Marc
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on June 12, 2015, 02:36:51 PM
Not sure why, but PEXPORTS seems to GPF just after reading the SetWindowsHookW function in User32.dll. The batch file continues and dlltool creates the *.a library, albeit with an incomplete file list.

I am not sure how I feel about the mangled vs. non-mangled names. I need to research it more to satisfy myself of the pros and cons of each method.

Thanks!
Paul
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Jim Dunn on August 11, 2015, 07:33:40 AM
Just an FYI... can't download either the binary or the source rar files...
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Paul Squires on August 15, 2015, 11:39:24 AM
Updated the original post and uploaded new files. I tweaked the dlltool.exe command line slightly in the generated .bat file that creates the necessary lib file. I also switched from using pexports.exe to gendef.exe in order to generate the DEF listing from the DLL. I find gendef to be more reliable than pexports which tended to GPF on complicated DLL's.

Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 06:21:45 AM
Why your tool insist in creating the .def file in the folder where the .dll is located instead of the folder where the .a library will be created? If the folder where the -def file will be written is write protected, it will fail, and dlltool won't provide any meaningful message, driving you crazy.

Code: [Select]
@echo off
set path=%path%;C:\Users\Pepe\FreeBasic32\bin\win32\
gendef.exe "C:\Windows\SysWOW64\propsys.dll"
dlltool.exe -D "C:\Windows\SysWOW64\propsys.dll" -d "C:\Windows\SysWOW64\propsys.def" -l "C:\Users\Pepe\FreeBasic64\tools\makelib\libpropsys.dll.a"
[code]
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 06:43:01 AM
If anybody can make an import library for propsys.dll 32-bit that works I will be gratefully indebted.

I have made one, but the linker fails.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: James Fuller on June 13, 2016, 12:22:18 PM
Jose,
  Try this one.

James
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 12:34:38 PM
Thanks very much. Apparently it works. I have called one of the functions and the test compiles and runs. Will have to do a more extensive test.

But what I would like to know is what I have to do to build a library that works, instead of having to beg for it, because there are many that I will need. What have you done? I have used the .def file that you posted an run dlltool. It has created a library, but the linker doesn't like it. Why?

Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: James Fuller on June 13, 2016, 01:56:00 PM
Jose,
  I don't know how you went about it so I will provide my method.
I have always used msys: http://www.mingw.org/wiki/msys for building Mingw compatible libraries.
The rage today is msys2 but it comes with it's own version of gcc/g++ and I never (spent little time) figured out how to tell it to use something else.
With msys I can edit the "msys/1.0/etc/fstab" file  to tell it which compiler/tools to use. You do have to exit and rerun after changing.
Some of the MinGW 64 bit compilers can produce 32bit executables but they are a pain to use with most of the library sources that use "configure" to set up a build of the library. I always install both the 64bit and 32bit versions so I can build 32/64 by changing the fstab entry.

For this specific case I installed both FreeBasic 32/64 along with the recommended Mingw gnu 32/64 toolchains and renamed them FbMingw32/FbMingw64 respectively.
I also have Visual Studio 2015 Community installed.

I downloaded the reimp source and built both 32 and 64 bit versions using FbMingw32/64. This is probably not necessary but... Many warnings on both builds but they both ran fine(?).

Now the search begins to find the propsys.lib files. I found them in two places:
64bit:
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64

32bit:
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib

I used the ones from the Windows Kits\8.1\.

I created folders for both 32/64 and copied the respective propsys.lib files to them
I also added the 32/64 bit versions of reimp.

I fired up msys and navigated to the folders. Remember to use /c/ for the drive and edit fstab.

$ cd /c/work/propsys32
$ reimp -d propsys.lib
Note the 32/64 def files will differ but the last line in each def file I believe is for use with C##.
_WinRTPropertyValueToPropVariant@8   @436
Delete this last line before running dlltool.

$ dlltool -k -d propsys.def -l libpropsys.a

That's it.:)

James
   


Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 02:16:51 PM
No, that's not all.

Why if I use dlltool -k -d propsys.def -l libpropsys.a in my computer the resulting library does not work?

Are you using the dlltool.exe that comes with FB or another one?
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 02:21:43 PM
Code: [Select]
[quote]
Now the search begins to find the propsys.lib files. I found them in two places:
64bit:
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib\x64

32bit:
C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\Lib

In Windows 7 you find the 64 bit one in System32, and the 32 bit one in SysWOW64 (the DLLs, not the LIBs).
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: James Fuller on June 13, 2016, 02:33:36 PM
I am using the dlltool from the FbMingw32/64.
The 32bit one creates a 32bit library the 64 a 64 library.

The .lib files are part of the Visual C++ sdk.

James
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 03:15:00 PM
> I am using the dlltool from the FbMingw32/64.

And there is a way to get them (both 32 and 64 bit) in binary form, without having to install MinGW, learn C programming and compile the source code?

Apparently, the Linux guys think that everybody has to learn C.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: James Fuller on June 13, 2016, 03:43:12 PM
They are included with both 32/64 FreeBasic.
Just make sure you use the right one.
James
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 13, 2016, 04:19:41 PM
reimp.exe is not included, and the libraries generated with dlltool.exe don't work, at least the ones that I've tried.

But it doesn't matter, I give up.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 14, 2016, 04:49:53 AM
I have tried the reimp.exe 32-bit that I have found in the web and it works.

Code: [Select]
reimp -d mCtrl.lib
dlltool -k -d mCtrl.def -l libmCtrl.dll.a

the .def file is different from the one generated by the other tools:

Code: [Select]
LIBRARY "mCtrl.dll"
EXPORTS
DllGetVersion@4
mcBeginBufferedAnimation@32
mcBeginBufferedPaint@20
mcBeginPanningFeedback@4
mcBufferedPaintClear@8
mcBufferedPaintInit@0
mcBufferedPaintRenderAnimation@8
mcBufferedPaintStopAllAnimations@4
mcBufferedPaintUnInit@0
mcButton_Initialize@0
mcButton_Terminate@0
mcChart_Initialize@0
mcChart_Terminate@0
mcCloseThemeData@4
mcCreateDialogIndirectParamA@24
mcCreateDialogIndirectParamW@24
mcCreateDialogParamA@24
mcCreateDialogParamW@24
mcDialogBoxIndirectParamA@24
mcDialogBoxIndirectParamW@24
mcDialogBoxParamA@24
mcDialogBoxParamW@24
mcDrawThemeBackground@24
mcDrawThemeBackgroundEx@24
mcDrawThemeEdge@32
mcDrawThemeIcon@28
mcDrawThemeParentBackground@12
mcDrawThemeParentBackgroundEx@16
mcDrawThemeText@36
mcDrawThemeTextEx@36
mcEnableThemeDialogTexture@8
mcEndBufferedAnimation@8
mcEndBufferedPaint@8
mcEndPanningFeedback@8
mcExpand_Initialize@0
mcExpand_Terminate@0
mcGetBufferedPaintBits@12
mcGetBufferedPaintDC@4
mcGetBufferedPaintTargetDC@4
mcGetBufferedPaintTargetRect@8
mcGetCurrentThemeName@24
mcGetThemeAppProperties@0
mcGetThemeBackgroundContentRect@24
mcGetThemeBackgroundExtent@24
mcGetThemeBackgroundRegion@24
mcGetThemeBitmap@24
mcGetThemeBool@20
mcGetThemeColor@20
mcGetThemeDocumentationProperty@16
mcGetThemeEnumValue@20
mcGetThemeFilename@24
mcGetThemeFont@24
mcGetThemeInt@20
mcGetThemeIntList@20
mcGetThemeMargins@28
mcGetThemeMetric@24
mcGetThemePartSize@28
mcGetThemePosition@20
mcGetThemePropertyOrigin@20
mcGetThemeRect@20
mcGetThemeStream@28
mcGetThemeString@24
mcGetThemeSysBool@8
mcGetThemeSysColor@8
mcGetThemeSysColorBrush@8
mcGetThemeSysFont@12
mcGetThemeSysInt@12
mcGetThemeSysSize@8
mcGetThemeSysString@16
mcGetThemeTextExtent@36
mcGetThemeTextMetrics@20
mcGetThemeTransitionDuration@24
mcGetWindowTheme@4
mcGrid_Initialize@0
mcGrid_Terminate@0
mcHitTestThemeBackground@40
mcHtml_Initialize@0
mcHtml_Terminate@0
mcImgView_Initialize@0
mcImgView_Terminate@0
mcIsAppThemed@0
mcIsCompositionActive@0
mcIsMenubarMessage@8
mcIsThemeActive@0
mcIsThemeBackgroundPartiallyTransparent@12
mcIsThemeDialogTextureEnabled@4
mcIsThemePartDefined@12
mcMditab_DefWindowProc@24
mcMditab_Initialize@0
mcMditab_Terminate@0
mcMenubar_HandleRebarChevronPushed@8
mcMenubar_Initialize@0
mcMenubar_Terminate@0
mcOpenThemeData@8
mcOpenThemeDataEx@12
mcSetThemeAppProperties@4
mcSetWindowTheme@12
mcSetWindowThemeAttribute@16
mcTable_AddRef@4
mcTable_Clear@8
mcTable_ColumnCount@4
mcTable_Create@12
mcTable_GetCellA@16
mcTable_GetCellW@16
mcTable_Release@4
mcTable_Resize@12
mcTable_RowCount@4
mcTable_SetCellA@16
mcTable_SetCellW@16
mcTheme_Initialize@0
mcTheme_Terminate@0
mcTreeList_Initialize@0
mcTreeList_Terminate@0
mcUpdatePanningFeedback@16
mcVersion@4

You would have saved me hours of headaches if you had posted reimp.exe as I requested, instead of the other tools that don't work with these visual basic libraries.

Now I need a reimp.exe for 64 bit.
Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: James Fuller on June 14, 2016, 06:53:33 AM
I must have missed your request, Sorry.
Attached find 32/64 reimp
James

Title: Re: MakeLIB - utility to create (*.a) import library from DLL (source included)
Post by: Josť Roca on June 14, 2016, 08:28:09 AM
Thanks very much. I have got it working.