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

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