I want to introduce you to Sphinx, a small code, which allows to create at a small Library (just that: lol:)
good, it is a little trick, but has the merit of working very well
to make a library, you must already write the code of a DLL
a DLL is a set of ProcedureDLL (), so nothing complicated!
for example, here I will use the following code which represents my future library:
Save it somewhere under the name (for example) " my_librairie.pb "
Code: Select all
; Exemple de Librairie a compiler en DLL
; Le fichier *.Lib sera generé avec le meme nom que votre DLL
; Code "operations.dll " a compiler en DLL
ProcedureDLL.i AttachProcess(Instance)
EndProcedure
; Called when the program release (free) the DLL ;
ProcedureDLL.i DetachProcess(Instance)
EndProcedure
;Both are called when a thread in a program call Or release (free) the DLL ;
ProcedureDLL.i AttachThread(Instance)
EndProcedure
ProcedureDLL.i DetachThread(Instance)
EndProcedure
;************** LA LIB ******************************
;START_LIB
ProcedureDLL.i addi(a,b)
ret=a+b
ProcedureReturn ret
EndProcedure
ProcedureDLL.i sous(a,b)
ret= a-b
ProcedureReturn ret
EndProcedure
ProcedureDLL.i divi(a,b)
ret=a/b
ProcedureReturn ret
EndProcedure
ProcedureDLL.i multi(a,b)
ret=a*b
ProcedureReturn ret
EndProcedure
;STOP_LIB
; Epb
for it to work, you must ABSOLUTELY put the line
at the beginning of the list of ProcedureDLL composing your lib;START_LIB
And
a The End !!;STOP_LIB
it is with these tags I repere the name of Procedures which will serve in the library ...
short for the test do not change anything:)
then you run "Sphinx", and you click on the only button "Make Lib"
Sphinx will ask you to choose the * .pb file from your DLL library (" my_librairie.pb " for our example)
do it, and confirm .... is all
Explanation
Sphinx will then load the file "my_librairie.pb"
read its contents and make a temporary import file with the names of the procedures "my_librairie.poi"
it will compile a Dll with the name "my_librairie.dll"
and generate at the same time a file *.lib ( "my_librairie.lib")
then it will generate an * Imp file ( "Lib_my_librairie.imp")
it will be generated in the location: "PureLibrairies/Windows" of your Purebasic !!
and finally will delete the temporary file "my_librairie.poi"
the functions of this library will always be available when you encode (just like Tailbite )
for example to test enter this code which resumes the use of one of the Proceduredll of our library
(Restart your compiler before )
Code: Select all
debug divi(10,2)
if you distribute your creations, do not forget to include the Dll and the Lib file created by Sphinx
The code Of Sphinx
Code: Select all
;***********************************************
;Titre :*Sphinx
;Auteur : Zorro
;Date :11/09/2017
;Heure :09:37:08
;Version Purebasic : PureBasic 5.60 (Windows - x86)
;Version de l'editeur :EPB V2.64
; Libairies necessaire : Aucune
;***********************************************
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Win
EndEnumeration
;}
;{ Gadgets
Enumeration
#Titre
#Text_1
#Button_Make
EndEnumeration
;}
;{ Fonts
Enumeration
#Font_Titre
EndEnumeration
;}
Define.l Event
;}
; **************************************************************************
Declare openwindow_win()
Declare create_poi(file_pb.s,file_poi.s,file_lib.s)
Declare compile_dll(file_pb.s,file_dll.s)
Declare.s compile_imp(file_poi.s, path_imp.s)
Enumeration
#file
EndEnumeration
Global Path_home.s=GetCurrentDirectory()
;;chemin_compiler_32$ =#PB_Compiler_Home+"Compilers\"+"pbcompiler.exe"
; ***************************************************************************
OpenWindow_Win()
;{- Event loop
Repeat
Event = WaitWindowEvent(12)
Select Event
; ///////////////////
Case #PB_Event_Gadget
Select EventGadget()
Case #Titre
Case #Text_1
Case #Button_Make
File_pb.s=OpenFileRequester( "choisir le fichier PB DLL_source",GetCurrentDirectory(),"*.*",0) ; fichier a compiler en DLL
Chemin_Travail.s=GetPathPart(File_pb.s)
File_dll.s=Chemin_Travail.s+GetFilePart(File_pb.s,#PB_FileSystem_NoExtension)+".dll"
File_lib.s=GetFilePart(File_pb.s,#PB_FileSystem_NoExtension)+".lib"
File_imp.s="Lib_"+ GetFilePart(File_pb.s,#PB_FileSystem_NoExtension)+".imp"
File_poi.s=Chemin_Travail.s+GetFilePart(File_pb.s,#PB_FileSystem_NoExtension)+".poi"
path_imp.s= Chr(34)+#PB_Compiler_Home + "PureLibraries\Windows\" + File_imp.s+Chr(34)
Create_POI(File_pb.s,File_poi.s,File_lib.s)
Compile_Dll(File_pb.s,File_dll.s)
compile_imp(File_poi.s, path_imp.s)
MessageRequester( "Rapport","La librairie "+ File_imp.s + " est crée "+Chr(10)+" a cet endroit : "+Chr(10)+#PB_Compiler_Home + "PureLibraries\Windows\")
End
EndSelect
; ////////////////////////
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Win
CloseWindow(#Win)
Break
EndSelect
EndSelect
ForEver
;
;}
;- Zone Procedures
Procedure OpenWindow_Win()
;by zorro
If OpenWindow(#Win, 568, 158, 260, 174, "Sphinx", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_TitleBar)
;If CreateGadgetList(WindowID(#Win))
TextGadget(#Titre, 60, 5, 140, 40, "SPHINX ")
TextGadget(#Text_1, 65, 45, 65, 15, "By Dobro")
ButtonGadget(#Button_Make, 75, 105, 105, 35, "Make Lib")
; Gadget Fonts
SetGadgetFont(#Titre, LoadFont(#Font_Titre, "Microsoft Sans Serif", 24, #PB_Font_Bold|#PB_Font_HighQuality))
;EndIf
EndIf
EndProcedure
;
Procedure Create_POI(File_pb.s,File_poi.s,File_lib.s)
;by zorro
NewList List.s()
OpenFile(#file,File_pb.s)
While Eof(#file) = 0
Ligne.s=ReadString(#file)
Ligne.s=Trim(Ligne.s," ") ; retire espaces
Ligne.s=Trim(Ligne.s,Chr(9)) ;retire TAB
If LCase(Ligne.s)=";stop_lib"
Flag=#False
CloseFile(#file)
; ecriture du poi
OpenFile(#File,File_poi.s)
WriteStringN(#file,"Import "+Chr(34)+File_lib.s+Chr(34))
ForEach List.s()
WriteStringN(#File,List.s())
Next
WriteStringN(#file,"EndImport")
CloseFile(#file)
ProcedureReturn
EndIf
If Flag=#True ; on creer la list
If FindString(Ligne.s,"ProcedureDll" ,1,#PB_String_NoCase)>0
AddElement(List.s())
posdep=FindString(Ligne.s,"(")
Ligne.s=ReplaceString( Ligne.s," ","",#PB_String_NoCase ,posdep)
List.s()=StringField(Ligne.s,2," ") ; recup ce qui suit "ProcedureDll"
EndIf
EndIf
If LCase(Ligne.s)=";start_lib"
Flag=#True ; la ligne suivante commence la lib
EndIf
Wend
CloseFile(#file)
EndProcedure
;
Procedure Compile_Dll(File_pb.s,File_dll.s)
;by zorro
Shared Sortie$
Compiler = RunProgram(#PB_Compiler_Home + "Compilers\pbcompiler.exe",File_pb.s + " /dll /exe " + File_dll.s, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Sortie$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
CloseProgram(Compiler)
EndIf
EndProcedure
;
Procedure.s compile_imp(File_poi.s, path_imp.s)
;by zorro
; Merci a Chi ;o)
Shared Sortie$
Compiler = RunProgram(#PB_Compiler_Home + "Compilers\pbcompiler.exe",File_poi.s + " --Import " + path_imp.s, "", #PB_Program_Open | #PB_Program_Read | #PB_Program_Hide)
If Compiler
While ProgramRunning(Compiler)
If AvailableProgramOutput(Compiler)
Sortie$ + ReadProgramString(Compiler) + Chr(13)
EndIf
Wend
CloseProgram(Compiler)
EndIf
DeleteFile(File_poi.s)
EndProcedure
;Epb
Demo Video here : https://youtu.be/YweWfWxALzs