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

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