Sphinx, the tailbite of the poor man

Share your advanced PureBasic knowledge/code with the community.
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Sphinx, the tailbite of the poor man

Post by dobro »

Hello,

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
;START_LIB
at the beginning of the list of ProcedureDLL composing your lib
And
;STOP_LIB
a The End !!
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 :lol:

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)
it will display "5" -->> (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
Last edited by dobro on Tue Sep 12, 2017 2:40 pm, edited 1 time in total.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Sphinx, the tailbite of the poor man

Post by Fig »

Thank you for sharing, Dobro. :D
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Sphinx, the tailbite of the poor man

Post by dobro »

Merci Fig ;)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Sphinx, the tailbite of the poor man

Post by Bisonte »

What is the sense of this ?
What is the bonus vs. includes ?
Your vid have only french texts, so I really understand nothing ;)
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Sphinx, the tailbite of the poor man

Post by Kwai chang caine »

Hello BISONTE :wink:

The DOBRO code is for try to replace easily TailleBite, but in more simple. (No ASM, no C++, just PB)
It's obviously not also powerfull than the real TailleBite, but finally it's nearly the same behaviour :wink:

Sphinx create a DLL, and use it, like if this one is a PB Lib
After using Sphinx, you can use all the function you have in your DLL, without call the DLL, or prototype, or includefile

After if you want sharing your code with your own functions, just share your DLL with your code

Fred have also the same idea with the tool "RootPb\SDK\DLL Importer\DLL Importer.exe", but in less simple :wink:
ImageThe happiness is a road...
Not a destination
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Sphinx, the tailbite of the poor man

Post by dobro »

@Bisonte :you want me to tell you how many times, I have to be forced to read stuff in English? :mrgreen:
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Sphinx, the tailbite of the poor man

Post by Kwai chang caine »

Dobro wrote:@Bisonte :you want me to tell you how many times, I have to be forced to read stuff in English? :mrgreen:
You have not read his signature :lol:
Bisonte in his signature wrote:English is not my native language...
i believe BISONTE have the same problem that you :mrgreen:
BISONTE is german :lol:
ImageThe happiness is a road...
Not a destination
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Sphinx, the tailbite of the poor man

Post by Bisonte »

Uh I'm caught :mrgreen:

Edit:

German Text :
Als ich mich wieder einmal über den Google Translator kaputtlachen konnte, suchte ich ein bisschen und stieß auf DEEPL. Dieser kleine Text wurde von dieser Seite von deutsch nach englisch übersetzt. Ohne dass ich daran irgendetwas geändert habe am Ergebnis.
Also kann ich diesen Übersetzer eher empfehlen als Google.

English directly translated :
When I found myself laughing at the Google Translator again, I searched a bit and came across DEEPL. This small text has been translated from German to English. Without me changing anything about the result.
So I can recommend this translator more than Google.

https://www.deepl.com/translator
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Sphinx, the tailbite of the poor man

Post by Kwai chang caine »

Thanks BISONTE 8)
Because a time, i have try to translate french to german and writing in german forum, and i took a big kicking necklace up my ass :lol:

Already in this forum, everybody understand me a little bit :oops: ...except the english or american man :lol: but this time, the deutch man not understand one of my words :oops:
Thanks to the great MASTER KIFFY...he cried out on the bad german man...and save little KCC :mrgreen:
You have a big chance to be german, because you not know how much hard it is to learn it....and again..i have try several month :oops:

Thanks a lot for your good link MASTER, i keep it preciously 8)
ImageThe happiness is a road...
Not a destination
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Sphinx, the tailbite of the poor man

Post by dobro »

Ich behalte auch Ihren Übersetzer :)
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5353
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Sphinx, the tailbite of the poor man

Post by Kwai chang caine »

Dobro wrote:.Ich behalte auch Ihren Übersetzer
It's like i said...not easy to understand your german sentence about "Alka selzer" :? :lol:
:lol:

"Alka selzer" = "French pharmaceuticals"
In french that wrote:C'est bien c'que j'disais...pas facile à comprendre ta phrase en allemand sur les "Alka selzer"
ImageThe happiness is a road...
Not a destination
User avatar
Bisonte
Addict
Addict
Posts: 1232
Joined: Tue Oct 09, 2007 2:15 am

Re: Sphinx, the tailbite of the poor man

Post by Bisonte »

Unfortunately, it's not yet possible to translate complete web pages, but I hope this will come soon.

@Dobro: You have to mention, that you have to copy the compiled dll to the PureBasic\Compiler\ Path...
Otherwise the "userlib" won't work. It would be better, if the "Sphinx" copied the dll file to the right place.

Code: Select all

#PB_Compiler_Home + "Compilers\"
PureBasic 6.10 LTS (Windows x86/x64) | Windows10 Pro x64 | Asus TUF X570 Gaming Plus | R9 5900X | 64GB RAM | GeForce RTX 3080 TI iChill X4 | HAF XF Evo | build by vannicom​​
English is not my native language... (I often use DeepL to translate my texts.)
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1252
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Sphinx, the tailbite of the poor man

Post by Paul »

Although the concept is there and I really wish it would work, the use of a DLL is severely limiting.
Tailbite allows direct access to PureBasic commands whereas DLL's do not.

Super simple example...

Code: Select all

ProcedureDLL ResizeMyWindow(WindowID.i,x.i,y.i,w.i,h.i)
  ResizeWindow(WindowID,x,y,w,h)
EndProcedure
Compiled with Tailbite you can resize a window by simply calling
ResizeMyWindow(#MainWindow,10,10,300,200)

Compiled as a DLL you cannot do this :(


Also a small but in your code... you need to put quotes around your Paths when using RunProgram else if you have code in a Path like
C:\My Cool Apps\TestProject\Test.pb
your code will try and use
Apps\TestProject\Test.pb
Image Image
User avatar
RSBasic
Moderator
Moderator
Posts: 1218
Joined: Thu Dec 31, 2009 11:05 pm
Location: Gernsbach (Germany)
Contact:

Re: Sphinx, the tailbite of the poor man

Post by RSBasic »

Great, thank you for sharing. :)
Image
Image
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Re: Sphinx, the tailbite of the poor man

Post by dobro »

Soon good news, about Tailbite's successor.
Falsam on the French Forum working on it :)

to make Real User Libs
Last edited by dobro on Sun Sep 24, 2017 9:40 am, edited 1 time in total.
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Post Reply