It is currently Fri Jan 18, 2019 10:43 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Sphinx, the tailbite of the poor man
PostPosted: Mon Sep 11, 2017 9:13 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Oct 31, 2004 10:54 am
Posts: 749
Location: France
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:

; 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
Quote:
;START_LIB
at the beginning of the list of ProcedureDLL composing your lib
And
Quote:
;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:
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:
;***********************************************
;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

_________________
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/


Last edited by dobro on Tue Sep 12, 2017 2:40 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Mon Sep 11, 2017 7:08 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 293
Location: Côtes d'Azur, France
Thank you for sharing, Dobro. :D

_________________
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x86 5.62


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 9:27 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Oct 31, 2004 10:54 am
Posts: 749
Location: France
Merci Fig ;)

_________________
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 11:06 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1010
What is the sense of this ?
What is the bonus vs. includes ?
Your vid have only french texts, so I really understand nothing ;)

_________________
PureBasic 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 1:29 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4378
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 3:03 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Oct 31, 2004 10:54 am
Posts: 749
Location: France
@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/


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 6:36 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4378
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 6:58 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1010
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 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 7:13 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4378
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Tue Sep 12, 2017 11:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Oct 31, 2004 10:54 am
Posts: 749
Location: France
Ich behalte auch Ihren Übersetzer :)

_________________
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Wed Sep 13, 2017 8:26 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4378
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Wed Sep 13, 2017 11:19 am 
Offline
Addict
Addict
User avatar

Joined: Tue Oct 09, 2007 2:15 am
Posts: 1010
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:
#PB_Compiler_Home + "Compilers\"

_________________
PureBasic 5.46 LTS / 5.62 (Windows x86/x64) | Windows10 Pro x64 | Z370 Extreme4 | i7 8770k | 32GB RAM | iChill GeForce GTX 980 X4 Ultra | HAF XF Evo​​
English is not my native language... (I often use DeepL to translate my texts.)


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Wed Sep 13, 2017 9:01 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 4:34 pm
Posts: 870
Location: Canada
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Mon Sep 18, 2017 2:36 pm 
Offline
Moderator
Moderator
User avatar

Joined: Thu Dec 31, 2009 11:05 pm
Posts: 721
Location: Berlin and Ibiza
Great, thank you for sharing. :)

_________________
ImageImageImageImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: Sphinx, the tailbite of the poor man
PostPosted: Fri Sep 22, 2017 6:18 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Oct 31, 2004 10:54 am
Posts: 749
Location: France
Soon good news, about Tailbite's successor.
Falsam on the French Forum working on it :)

to make Real User Libs

_________________
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/


Last edited by dobro on Sun Sep 24, 2017 9:40 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye