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

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