Search code examples
windowsvisual-studiofortranenvironment-variablesintel-fortran

Get Solution Directory in Intel Visual Fortran


Is there a way within an Intel Visual Fortran project to get a string representing the Visual Studio Solution Directory?

Get_Environment_Variable doesn't seem to have that ability as far as I can tell.

Intel Fortran 2017 and VS 2015.


Solution

  • From your other comments, it seems to me that you're possibly more interested in the directory containing the executable. If you know your solution directory structure you can work out the solution location from that.

    You do this in two steps. First you call the Windows API routine GetModuleHandle, passing NULL as the argument. This returns a handle to the current executable. Then you pass this handle to GetModuleFileName which returns the path to the executable as a NUL-terminated string.

    If you wanted to separate out just the path, you could use the Intel library routine SPLITPATHQQ.

    Example:

    program whereami
    use kernel32
    use, intrinsic :: ISO_C_BINDING
    implicit none
    
    integer(HANDLE) :: h
    character(MAX_PATH) :: f
    integer(DWORD) :: ret
    
    
    h = GetModuleHandle (NULL)
    ret = GetModuleFileName (h,f,len(f))
    print *, f(1:index(f,C_NULL_CHAR)-1)
    end program whereami