- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to get a full path where the executable is located at run-time. So here's what I'm trying:
program main
use KERNEL32
CHARACTER*500 path
integer(LPSTR) path1
CHARACTER*200 filename
integer(DWORD) dum
path1=0
filename='WideString.exe'
dum = GetFullPathName(filename, 500, path, path1)
if(dum .eq. 0)then
dum=GetLastError()
print *, dum
endif
print *, path
end
'WideString.exe' is the name of the executable. Similar code works well in C++, but not in Fortran.
Any idea what I'm doing wrong or a better way to accomplish this?
I forgot the mention...GetFullPathName and GetLastError both return 0, and the variable path ends up being a blank string.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
filename='WideString.exe'C
You also need to either search for the trailing NUL in the return value or use the function return value for the length.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ah, thank you!
Only GetFullPathName returned the current path, rather than executable's path. Any better functions to accomplish this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The routine you want is
INTEGER :: nc
CHARACTER(LEN=255) :: fpname
nc = GetModuleFileName(GetModuleHandle('MYPROG.EXE'C), fpname, LEN(fpname))
where you supply the name of your running executable and fpname is returned with the full UNC path.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page