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

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