Oxygen Basic

Programming => Example Code => General => Topic started by: Charles Pegge on May 03, 2014, 02:01:55 AM

Title: GetExePath
Post by: Charles Pegge on May 03, 2014, 02:01:55 AM
Extraction of ExePath from the commandline:

Code: [Select]

'include $/inc/minwin.inc

! GetCommandline "GetCommandLineA" lib "kernel32.dll"

function GetExePath() as string
================================
char* s=getCommandline
byte *b=strptr s
sys bb=@b,bs=@b,mm=0,ms=0
do
  select case b
  case 0  : exit do
  case 32 : if mm=0 : exit do '   space (no quote at start)
  case 34 : if mm   : exit do ' " double quote
            mm=@b
            bs=@b+1
  case 47 : ms=@b             ' / fwd slash
  case 92 : ms=@b             ' \ back slash
  end select
  @b++
end do
if ms then return mid s,bs-bb+1,ms-bs+1 'includes end slash
end function

print GetExePath

Title: Re: GetExePath
Post by: Charles Pegge on May 09, 2014, 10:02:32 PM
More directly, using GetModuleFileName

Code: [Select]
! GetModuleFileName "GetModuleFileNameA" lib "kernel32.dll"


function GetExePath() as string
===============================
char s[256]
byte *b=strptr s
GetModuleFileName 0,@b,256
sys i
do
  select b
  case 0  : exit do
  case 92 : i=@b
  end select
  @b++
end do
return left s,i-strptr(s)+1 'includes final slash
end function

print GetExePath