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

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