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

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