PureLibrary Helper Functions

Share your advanced PureBasic knowledge/code with the community.
Axolotl
Addict
Addict
Posts: 885
Joined: Wed Dec 31, 2008 3:36 pm

PureLibrary Helper Functions

Post by Axolotl »

There are (at least two) nice tools to build PureLibraries with the IDE.
Thanks to mk-soft => LIB-PB v6.20+: IDE-Tool Build Library for all OS
and pf shadoko => PureLibrary Creator - PB 6.20

In my own experiments, I have created the following functions. For now they are windows only, but perhaps in the future .....
1. RestartCompilerNow() ; works only on windows
2. CompilerConfig_GetSaveSettingsMode()

Code: Select all

Procedure RestartCompilerNow() 
  Protected hwnd, item$, position 
  Protected hMenu, hSubMenu, wParam, mii.MENUITEMINFO 

CompilerSelect #PB_Compiler_OS 
  CompilerCase #PB_OS_Windows 
    hwnd = Val(GetEnvironmentVariable("PB_TOOL_MainWindow"))  ;  - OS handle to the main IDE window 
    If hwnd = 0  ; fall back and testing 
      hwnd = FindWindow_(0, @"PureBasic 6.30 beta 2 (x64)")  ; use your IDE 
    EndIf 
    If hwnd 
      Debug "PureBasic IDE found ..... " 
      hMenu = GetMenu_(hwnd) 
      If hMenu 
        ; File 0) | Edit (1) | Project (2) | Form (3) | Compiler (4) | Debugger (5) .... 
        hSubMenu = GetSubMenu_(hMenu, 4)  ; zero-based item (by position) 
        If hSubMenu 
          mii\cbSize = SizeOf(MENUITEMINFO) 
          mii\fMask  = #MIIM_STRING | #MIIM_ID 
          mii\dwTypeData = 0
          ; count zero-based menu items (don't forget the MenuBar) 
          position = 7 ; Restart Compiler 
        ; position = 9 ; Options // Test successfully -> the dialog is open 
          If GetMenuItemInfo_(hSubMenu, position, #True, @mii) 
            mii\cch + 1  ; needed for the entire text <??>
            item$ = Space(mii\cch) 
            mii\dwTypeData = @item$  ; pointer to allocated memory 
            If GetMenuItemInfo_(hSubMenu, position, #True, @mii) 
              Debug "  Menu Item    = '" + item$ + "'"    ;  == "Re&start Compiler" 
              Debug "  Menu Item ID = " + mii\wID  
              wParam = (mii\wID & $FFFF)                  ; LoWord is IDM_* 
              PostMessage_(hwnd, #WM_COMMAND, wParam, 0)  ; let the IDE restart the compiler ?? 
            EndIf 
          EndIf
        EndIf 
      EndIf 
    Else 
      Debug "PureBasic IDE not found "
    EndIf 
; CompilerCase #PB_OS_Linux   
; CompilerCase #PB_OS_MacOS 
CompilerEndSelect 

; ProcedureReturn 0 
EndProcedure 

Code: Select all

; CCS := CompilerConfigStorage 
;
Enumeration ECompilerConfigStorage 
  #CCS_EndOfFile    ; == 0
  #CCS_PerFileCfg   ; == 1
  #CCS_PerFolderCfg ; == 2
  #CCS_DoNotSave    ; == 3
EndEnumeration 

; PureBasic.prefs 
; [Global] 
; .....
; SaveSettingsMode = 0 
; .....
; #PB_TOOL_Preferences  .. Full path and filename of the IDE's Preference file

Procedure CompilerConfig_GetSaveSettingsMode()  ; returns #CCS_X 
  Protected result, prefsfile$ 

  prefsfile$ = ""               ; (default) 
  result     = #CCS_DoNotSave   ; (default) 
  prefsfile$ = GetEnvironmentVariable("PB_TOOL_Preferences")  ; the full filename including path !! 
  If Not Asc(prefsfile$)  ; fall back and testing 
    CompilerSelect #PB_Compiler_OS 
      CompilerCase #PB_OS_Windows ; standard installation stores the stuff here ?? 
        prefsfile$ = GetEnvironmentVariable("APPDATA") + "\PureBasic\PureBasic.prefs" 
     ;CompilerCase #PB_OS_Linux   
     ;CompilerCase #PB_OS_MacOS   
    CompilerEndSelect 
  EndIf 
  If Asc(prefsfile$) And OpenPreferences(prefsfile$) ; take a closer look 
    PreferenceGroup("Global") 
    result = ReadPreferenceInteger("SaveSettingsMode", #CCS_DoNotSave) 
    ClosePreferences() 
  EndIf 
  ProcedureReturn result 
EndProcedure 

Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Quin
Addict
Addict
Posts: 1154
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: PureLibrary Helper Functions

Post by Quin »

Very nice, thanks! I've been playing with purelibraries a lot recently
Fred
Administrator
Administrator
Posts: 18372
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PureLibrary Helper Functions

Post by Fred »

The pfshadoko tool is now shipped in the compilers directory so it should be easy to add a tool in the IDE to use it
Quin
Addict
Addict
Posts: 1154
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: PureLibrary Helper Functions

Post by Quin »

Ah yes, I see that, very nice! Although here's a fun bug, try to run it with -h as an argument it crashes and shows a this program has stopped working dialog for me :twisted:
acreis
Enthusiast
Enthusiast
Posts: 247
Joined: Fri Jun 01, 2012 12:20 am

Re: PureLibrary Helper Functions

Post by acreis »

Fred wrote: Wed Nov 05, 2025 8:38 pm The pfshadoko tool is now shipped in the compilers directory so it should be easy to add a tool in the IDE to use it
Hi Fred!

The tool shipped with purebasic doesn't work for me. There is a window (console?) showing and disapearing in a blink of eye. Only to give some feedback, as the version built from source code works for me.

Tip: to create resident files (macros, enumerations, etc ...), put it between lines ';Residents' and ';EndResidents':

Code: Select all

;Residents
Enumeration CWO_Positioning
  #CWO_ActiveWindowPos = -1
  #CWO_AbsolutePos     = -2
  #CWO_MonitorPos      = -3
EndEnumeration

Enumeration CWO_PositionAnchor
  #CWO_Center = 0
  #CWO_TopLeft
  #CWO_TopRight
  #CWO_BottomLeft
  #CWO_BottomRight
EndEnumeration
;EndResidents


Thanks!
Axolotl
Addict
Addict
Posts: 885
Joined: Wed Dec 31, 2008 3:36 pm

Re: PureLibrary Helper Functions

Post by Axolotl »

Opps, another interessting thing:
If you call the pbcompilerc -h the text says that /PURELIBRARY is a windows specific option.
Is the information perhaps out of date?
Or my version is too old. (6.30 b2)?
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
Post Reply