Win32 - Get filename of your running Application

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Win32 - Get filename of your running Application

Post by BackupUser »

Code updated For 5.20+ (same As ProgramFilename())

Restored from previous forum. Originally posted by MrVainSCL.

hi @ all
here is small Win32 API example how to get the filename of your running application. :wink:

Code: Select all

; ------------------------------------------------------------
;
; PureBasic Win32 API - Get filename of your App - Example v1.0
;
; by Tranquilizer & MrVainSCL!     04/Dec/2002    PB v3.40+
;
; ------------------------------------------------------------
;
    Global filename$
    ;
    Procedure MyGetFilename()
        hMod = GetModuleHandle_(0)
        tmp$ = Space(255)
        GetModuleFilename_(hMod,@tmp$,255)
        filename$ = GetFilePart(tmp$)
    EndProcedure
    ;    
    MyGetFilename()
    MessageRequester("The filename of your application is:",filename$,0)
End
;
; ------------------------------------------------------------



PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Code: Select all

Procedure.s ExeFilename()
  tmp$ = Space(1000)
  GetModuleFilename_(0,@tmp$,1000)
  ProcedureReturn GetFilePart(tmp$)
EndProcedure

Procedure.s ExePath()
  tmp$ = Space(1000)
  GetModuleFilename_(0,@tmp$,1000)
  ProcedureReturn GetPathPart(tmp$)
EndProcedure

MessageRequester("INFO","Path: "+ExePath()+Chr(13)+"FileName: "+ExeFileName(),0)
cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

Or both again, but with even shorter code:

Code: Select all

a$=Space(255) : GetModuleFilename_(0,@a$,255) ; Prepare details.
appfolder$=GetPathPart(a$) ; Get app's folder.
appname$=GetFilePart(a$) ; Get app's name.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

You dont need GetModuleHandle_(0).

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by PB.

> You dont need GetModuleHandle_(0).

Thanks for the info... my tip has been modified as a result.

Thanks to MrVainSCL too for sharing his original version. :)
Post Reply