by selecting a 'mydll.lib' file, this program generates automatically
1/ 'mydll.pb' --> Code Block for Import/EndImport
2/ 'mydll.res' --> Resident file to be put into 'purebasic/residents/'
Code: Select all
Procedure.s MakeFn(fn.s, len.l)
Protected i.l
fn + ".l("
If len
For i = 1 To (len/4)
fn + Chr(96+i) + ".l, "
Next
fn = Left(fn, Len(fn)-2)
EndIf
ProcedureReturn fn + ") ; " + Str(len)
EndProcedure
Procedure.l IsFn(List fn.s(), name.s)
ForEach fn()
If fn() = name
ProcedureReturn #True
EndIf
Next
EndProcedure
Procedure.l ImportLib(libName.s)
Protected NewList fn.s()
Protected line.s, name.s, arg.s
If ReadFile(0, libName)
While Eof(0) = #False
line = ReadString(0)
If Left(line, 7) = "__imp__"
arg = StringField(line, 2, "@")
If arg
name = MakeFn(Mid(line, 8, Len(line)-Len(arg)-8), Val(arg))
If IsFn(fn(), name) = #False
AddElement(fn()) : fn() = name
EndIf
EndIf
EndIf
Wend
CloseFile(0)
EndIf
If ListSize(fn())
SortList(fn(), 0)
If CreateFile(1, Left(libName, Len(libName)-4) + ".pb")
WriteStringN(1, "; imported with purebasic v" + StrF(#PB_Compiler_Version, 1))
WriteStringN(1, "Import " + #DQUOTE$ + libName + #DQUOTE$)
ForEach fn()
WriteStringN(1, #TAB$ + fn())
Next
WriteStringN(1, "EndImport")
CloseFile(1)
ProcedureReturn #True
EndIf
EndIf
EndProcedure
libName.s = OpenFileRequester("Select .lib file", GetCurrentDirectory(), "*.lib|*.lib", 0)
If libName
libName = GetFilePart(libName)
If ImportLib(libName)
libName = Left(libName, Len(libName)-4)
RunProgram(libName+".pb")
RunProgram(#PB_Compiler_Home+"compilers/pbcompiler.exe","/RESIDENT "+libName+".res "+libName+".pb ",GetCurrentDirectory())
EndIf
EndIf
End