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

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