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

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