now I had to make my 5th wrapper and it is a lot of stupid typing.
So I thouhgt about a tool to do the 'stupid' part of the work.
Save it as MakeWrapper.pb
Code: Select all
;
; MakeWrapper
;
; by BKK (infratec), ts-soft
;
#Version$ = "1.04"
#WithTest = #True
Procedure.i MakeWrapper(Filename$, Array Functions.s(1))
Result = #False
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
WrapperFile$ = Left(Filename$, Len(Filename$) - 3) + "pbi"
CompilerDefault
WrapperFile$ = GetFilePart(Filename$)
WrapperFile$ = Left(WrapperFile$, FindString(WrapperFile$, ".") - 1)
WrapperFile$ = Left(Filename$, FindString(Filename$, WrapperFile$) + Len(WrapperFile$) - 1) + ".pbi"
CompilerEndSelect
Wrapper = CreateFile(#PB_Any, WrapperFile$)
If Wrapper
LibName$ = ReplaceString(GetFilePart(WrapperFile$), ".pbi", "")
WriteStringN(Wrapper, ";")
WriteStringN(Wrapper, "; " + LibName$)
WriteStringN(Wrapper, ";")
WriteStringN(Wrapper, "; a wrapper for " + GetFilePart(Filename$))
WriteStringN(Wrapper, ";")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "CompilerSelect #PB_Compiler_OS")
WriteStringN(Wrapper, " CompilerCase #PB_OS_Windows")
WriteStringN(Wrapper, " Global " + LibName$ + "_Filename$ = " + #DQUOTE$ + GetFilePart(Filename$) + #DQUOTE$)
WriteStringN(Wrapper, " Macro OSPrototype")
WriteStringN(Wrapper, " Prototype")
WriteStringN(Wrapper, " EndMacro")
WriteStringN(Wrapper, " CompilerCase #PB_OS_Linux")
WriteStringN(Wrapper, " Global " + LibName$ + "_Filename$ = " + #DQUOTE$ + ReplaceString(GetFilePart(WrapperFile$), ".pbi", ".so") + #DQUOTE$)
WriteStringN(Wrapper, " Macro OSPrototype")
WriteStringN(Wrapper, " PrototypeC")
WriteStringN(Wrapper, " EndMacro")
WriteStringN(Wrapper, " CompilerCase #PB_OS_MacOS")
WriteStringN(Wrapper, " Global " + LibName$ + "_Filename$ = " + #DQUOTE$ + ReplaceString(GetFilePart(WrapperFile$), ".pbi", ".so") + #DQUOTE$)
WriteStringN(Wrapper, " Macro OSPrototype")
WriteStringN(Wrapper, " PrototypeC")
WriteStringN(Wrapper, " EndMacro")
WriteStringN(Wrapper, "CompilerEndSelect")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
For i = 0 To ArraySize(Functions())
WriteStringN(Wrapper, "OSPrototype.i Proto_" + Functions(i) + "()")
Next i
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
For i = 0 To ArraySize(Functions())
WriteStringN(Wrapper, "Global " + Functions(i) + ".Proto_" + Functions(i))
Next i
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "Global " + LibName$ + ".i")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "Procedure.i " + LibName$ + "_LibInit()")
WriteStringN(Wrapper, " ")
WriteStringN(Wrapper, " Result = #False")
WriteStringN(Wrapper, " ")
WriteStringN(Wrapper, " " + LibName$ + " = OpenLibrary(#PB_Any, " + LibName$ + "_Filename$" + ")")
WriteStringN(Wrapper, " if " + LibName$)
For i = 0 To ArraySize(Functions())
WriteStringN(Wrapper, " " + Functions(i) + " = GetFunction(" + LibName$ + ", " + #DQUOTE$ + Functions(i) + #DQUOTE$ + ")")
CompilerIf #WithTest
WriteStringN(Wrapper, " If " + Functions(i) + " = #Null : Result + 1 : EndIf")
CompilerEndIf
Next i
WriteStringN(Wrapper, " ")
WriteStringN(Wrapper, " If Result = #False")
WriteStringN(Wrapper, " Result = #True")
WriteStringN(Wrapper, " Else")
WriteStringN(Wrapper, " Result = #False")
WriteStringN(Wrapper, " EndIf")
WriteStringN(Wrapper, " EndIf")
WriteStringN(Wrapper, " ")
WriteStringN(Wrapper, " ProcedureReturn Result")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "EndProcedure")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "")
WriteStringN(Wrapper, "Procedure " + LibName$ + "_LibFree()")
WriteStringN(Wrapper, " If IsLibrary(" + LibName$ + ") : CloseLibrary(" + LibName$ + ") : EndIf")
WriteStringN(Wrapper, " " + LibName$ + " = 0")
WriteStringN(Wrapper, "EndProcedure")
CloseFile(Wrapper)
Result = #True
EndIf
ProcedureReturn Result
EndProcedure
CompilerSelect #PB_Compiler_OS
CompilerCase #PB_OS_Windows
Filename$ = OpenFileRequester("Select the library file", "", "Libraries|*.dll;*.ocx;*.drv;*.cpl;*.sys", 0)
CompilerDefault
Filename$ = OpenFileRequester("Select the library file", "", "Libraries (lib*)|lib*", 0)
CompilerEndSelect
If Filename$
Library = OpenLibrary(#PB_Any, Filename$)
If Library
FunctionCount = CountLibraryFunctions(Library)
Dim Function.s(FunctionCount - 1)
If ExamineLibraryFunctions(Library)
i = 0
While NextLibraryFunction()
Function(i) = LibraryFunctionName()
i + 1
Wend
If MakeWrapper(Filename$, Function())
Text$ = "A skeleton of the wrapper exists now." + #LF$
Text$ + "But you still have to edit the filename" + #LF$
Text$ + "and the prototypes of the functions." + #LF$
Text$ + #LF$
Text$ + "Good luck !"
MessageRequester("Info", Text$)
EndIf
EndIf
CloseLibrary(Library)
EndIf
EndIf
Bernd