IonicWind Software

IWBasic => General Questions => Topic started by: zaphod on October 30, 2009, 02:59:17 PM

Title: how to get exename ?
Post by: zaphod on October 30, 2009, 02:59:17 PM
The function getstartpath get the path of executable. Ok.
I need also the name of executable for save a ini file with same name (even if user modify name)...
Is it possible ?
Title: Re: how to get exename ?
Post by: Ionic Wind Support Team on October 30, 2009, 03:08:20 PM
Use the API function GetModuleFileName

DECLARE "kernel32",GetModuleFileNameA(hmod as UINT,path as STRING,length as INT),INT
string name
GetModuleFileNameA(0,name,255)
print name
Title: Re: how to get exename ?
Post by: zaphod on October 31, 2009, 11:23:11 AM
hello,
thanx very much.

here is my code if could help someone :

                def name as STRING
DECLARE "kernel32",GetModuleFileNameA(hmod as UINT,path as STRING,length as INT),INT
name=SPACE$(255)
getmodulefilename(0,name,255)
name=extractfilename(name)


and filename functions :


sub extractfilename(fname as string),string
                def q,p=1 as INT
DO
q=instr(fname,"\\",p)
if q
p=q+1
ENDIF
until q=0
return right$(fname,len(fname)-p+1)
ENDSUB

sub extractfilepath(fname as string),string
                def q,p=1 as INT
DO
q=instr(fname,"\\",p)
if q
p=q+1
ENDIF
until q=0
return LEFT$(fname,p-1)
ENDSUB


Maybe its a good idea to insert into EB some filename functions.
In Pure Basic there is : GetFilePart / GetPathPart
In BlitzMax : StripDir$ / StripExt$/ ExtractDir$ / ExtractExt$
Title: Re: how to get exename ?
Post by: LarryMc on November 01, 2009, 06:34:26 PM
Those functions and more are available in Fletchie's "ctl.lib"

You can download it here:

http://www.ionicwind.com/forums/index.php/topic,1608.msg15133.html#msg15133

Larry
Title: Re: how to get exename ?
Post by: zaphod on November 02, 2009, 05:54:09 AM
Thanx for the ctl.lib : sounds good.
Must be include into EB...