Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

GETARG(0,buffer) call

niels_veldhuijzen
314 Views
Dear Forum members,
Sometimes the calling sequence GETARG(0,BUFFER) just gives me the file name of the program running (as it should be, according to the manual); but many times it returns the whole path (e.g. "C:MYFOLDERYOURFOLDERHERFOLDERHISPROGRAM.EXE"). I have two questions about this behaviour:
1) In what conditions will the whole path be returned by the calling sequence?
2) Is there any method (apart from using assembly language and learning about the entrails of Windows) to always getting the whole path?
I am using Intel VF 9.1 on WindowsXP Professional.
Yours sincerely,
Niels H. Veldhuijzen
Cito, Arnhem, The Netherlands
0 Kudos
2 Replies
Steven_L_Intel1
Employee
314 Views
I don't know why you see different values - it may have to do with how the program was invoked. But the following always works:


use kernel32
implicit none

integer(HANDLE) :: self
character(MAX_PATH) :: path
integer :: pathlen

! Get handle to self
self = GetModuleHandle(NULL)
! Get path of self
pathlen = GetModuleFileName (self, path, len(path))
! Display path
write (*,*) "Hi, I'm ", path(1:pathlen)

end
0 Kudos
niels_veldhuijzen
314 Views

Dear Steve (and all),

Thank you very much. I see I have to refresh my memory on APIs. Actually, the manual says that GETARG(0,BUFFER) gives you the first thing there is on the command line. Usually this is the program name. But, of course, many times you don't see any command line; e.g. when you activate a program by clicking its name in the file selector. As, in our application,it is of paramount importance to get the name of the folder the program is residing in, your API workaround is wonderful!

Yours sincerely,

Niels H. Veldhuijzen, Arnhem, The Netherlands

0 Kudos
Reply