Tech Articles


How to get the application path


This example shows how to get the application path for development and deployment environments. This is compatible with PB 12.6.

I recommend to use a NVO to develop this functionality.

1. First declare the Local External Functions:

FUNCTION int GetModuleFileNameW(&
           ulong hinstModule, &
           REF string lpszPath, &
           ulong cchPath) LIBRARY "KERNEL32.DLL"

FUNCTION ulong GetCurrentDirectoryW (&
  ulong textlen, &
  REF string dirtext) LIBRARY "KERNEL32.DLL"

 

2. And then create the function of_getapplicationpath():

ULong  lul_rc, lul_size
LONG  ll_last, ll_i, ll_handle
STRING ls_ApplicationPath = Space (255)
STRING ls_separator = "\"

//Get the handle of the application
ll_handle = Handle (GetApplication ())

//When handle is 0, it is in Development Environment.
IF ll_handle = 0 THEN
 lul_rc = GetCurrentDirectoryW(255, ls_ApplicationPath)
 Return ls_ApplicationPath
END IF

//When it is in Deployment Environment
GetModuleFileNameW(ll_Handle, ls_ApplicationPath, 254)

ll_i = 0
Do
 ll_last = ll_i
 ll_i = Pos (ls_ApplicationPath, ls_separator, ll_i + 1)
Loop Until ll_i = 0

Return Left (ls_ApplicationPath, ll_last - 1)

 

I hope it helps.

Comments (0)
There are no comments posted here yet

Find Articles by Tag

OLE Database Table SQL Server License RibbonBar DataWindow JSON DragDrop Icon Syntax PostgreSQL UI Modernization Error PowerScript (PS) Database Painter UI PBVM Repository Event Handling PBNI PDFlib Class UI Themes Database CoderObject Open Source BLOB Charts MessageBox .NET DataStore Configuration Installation Oracle .NET Std Framework SnapObjects Web API Branch & Merge Visual Studio Data Migration Authorization Interface SQL OAuth Encryption Automated Testing Sort PowerBuilder Event Testing Source Code Trial Performance Debugging DataType External Functions Validation Database Table Schema Expression File WinAPI SVN TFS Database Object PDF REST Platform Outlook Service ActiveX TreeView DataWindow Import JSON Transaction Array Stored Procedure SDK CI/CD PowerServer Mobile HTTPClient Filter Export JSON Windows OS Jenkins ODBC Debugger API Design 32-bit Windows 10 Icons Export SOAP RESTClient PBDOM Git OAuth 2.0 PowerBuilder Compiler WebBrowser .NET Assembly Database Table Data Excel PowerBuilder (Appeon) JSONParser PowerServer Web SqlExecutor XML Azure Model iOS DevOps Web Service Proxy CrypterObject Messagging SnapDevelop Debug Bug InfoMaker Import Elevate Conference Resize JSONGenerator Menu PFC C# Source Control Graph Text Event Handler Deployment RichTextEdit Control Database Profile Encoding Variable SqlModelMapper TortoiseGit COM Mobile Application TLS/SSL 64-bit Authentication RibbonBar Builder NativePDF Linux OS JSON IDE PostgreSQL ODBC driver Script Android Database Connection DLL GhostScript Window OrcaScript