Intel® Fortran Compiler 17.0 Developer Guide and Reference

Using Visual Studio* IDE Automation Objects (Windows*)

This topic briefly describes the Automation interfaces provided by Intel® Visual Fortran. Automation interfaces are programmable objects used to access underlying IDE components and projects to provide experienced developers with a means of automating common tasks and allow a finer degree of control over the IDE and the Fortran projects being used within it.

You can use the Visual Studio* Object Browser (View > Object Browser) to view an object and its associated properties. Open the following in the browser: Browse > Edit Custom Component Set > .NET > Microsoft.VisualStudio.VFProject.

Note

The objects listed here are provided as an advanced feature for developers who are already familiar with using Automation objects and the Visual Studio* object model.

Object

Description

IVFCollection

Contains the functionality that can be exercised on a collections object.

VFConfiguration

Programmatically accesses the properties in the General property page of a project's Property Pages dialog box. This object also allows access to the tools used to build this configuration.

VFCustomBuildTool

Programmatically accesses the properties in the Custom Build Step property page in a project's Property Pages dialog box.

VFDebugSettings

Contains properties that allow the user to programmatically manipulate the settings in the Debug property page.

VFFile

Describes the operations that can take place on a file in the active project.

VFFileConfiguration

Contains build information about a file (VFFile object), including such things as what tool is attached to the file for that configuration.

VFFilter

Exposes the functionality on a folder in Solution Explorer for an Intel® Visual Fortran project.

VFFortranCompilerTool

Exposes the functionality of the IFORT tool.

VFFortranCompilerVersion

Provides access to properties relating to the Intel® Visual Fortran compiler version.

VFLibrarianTool

Exposes the functionality of the LIB tool.

VFLinkerTool

Exposes the functionality of the LINK tool.

VFManifestTool

Programmatically accesses the properties in the Manifest Tool folder of a project's Property Pages dialog box.

VFMidlTool

Programmatically accesses the properties in the MIDL folder of a project's Property Pages dialog box.

VFPlatform

Provides access to properties relating to supported platforms.

VFPreBuildEventTool

Programmatically accesses the properties on the Pre-Build Event property page, in the Build Events folder in a project's Property Pages dialog box.

VFPreLinkEventTool

Programmatically accesses the properties on the PreLink Event property page, in the Build Events folder in a project's Property Pages dialog box.

VFPostBuildEventTool

Programmatically accesses the properties on the Post-Build Event property page, in the Build Events folder in a project's Property Pages dialog box.

VFProject

Exposes the properties on an Intel® Visual Fortran project

VFResourceCompilerTool

Programmatically accesses the properties in the Resources folder in a project's Property Pages dialog box.

The following example, written in Visual Basic*, demonstrates how to use automation objects to modify the list of available platforms and versions in the Visual Studio* IDE Configuration Manager:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Imports Microsoft.VisualStudio.VFProject
Imports System.Collections
Public Module MultiPV
    ' Create a Console application before executing this module
    ' Module demonstrates Multi Platform & Multi Version Automation Support
    ' Variable definition
    Dim Prj As Project          ' VS project
    Dim VFPrj As VFProject     ' Intel VF project
    Dim o As Object             ' Object
    Sub run()
        ' Get the Project
        Prj  = DTE.Solution.Projects.Item(1)
        '
        ' Get Intel VF project
        VFPrj  = Prj.Object
        '
        ' Get list of Supported platforms
        Dim pList As ArrayList = New ArrayList()    ' list of platforms
        Dim cList As ArrayList = New ArrayList()    ' lost of compilers
        Dim i As Integer
        pList  = getSupportedPlatforms()
        For i = 0 To pList.Count - 1
            cList  = getCompilers(pList.Item(i))
            printCompilers(pList.Item(i), cList)
        Next
        '
        ' Add configurations - x64
        For i = 0 To pList.Count - 1
            If pList.Item(i) <> "Win32" Then
                addConfiguration(pList.Item(i))
            End If
        Next
        Dim cfgsList As ArrayList = New ArrayList() ' list of configurations
        cfgsList = getAllConfigurations()
        '
        ' Set compiler
        For i = 0 To pList.Count - 1
            Dim pNm As String
            Dim cvList As ArrayList = New ArrayList()
            pNm = pList.Item(i)
            cList = getCompilers(pNm)
            cvList = getCompilerVersions(pNm)
            Dim j As Integer
            For j = 0 To cvList.Count - 1
                Dim cv As String = cvList.Item(j)
                If SetCmplrForPlatform(pNm, cv) Then
                    setActiveCfg(pNm)
                    SolutionRebuild()
                    Dim sOut As String = GetOutput()
                    Dim scv As String = CheckCompiler(sOut)
                    MsgBox(pNm + " " + cv + " " + scv)
                End If
            Next
        Next
    End Sub
    ' get context from Output window
    Function GetOutput() As String
        Dim win As Window
        Dim w As OutputWindow
        Dim wp As OutputWindowPane
        Dim td As TextDocument
        win = DTE.Windows.Item(Constants.vsWindowKindOutput)
        w = win.Object
        Dim i As Integer
        For i = 1 To w.OutputWindowPanes.Count
            wp = w.OutputWindowPanes.Item(i)
            If wp.Name = "Build" Then
                td = wp.TextDocument
                td.Selection.SelectAll()
                Dim ts As TextSelection = td.Selection
                GetOutput = ts.Text
                Exit Function
            End If
        Next
    End Function
    Function CheckCompiler(ByVal log As String) As String
        Dim s As String
        Dim beg_ As Integer
        Dim end_ As Integer
        beg_ = log.IndexOf("Compiling with")
        beg_ = log.IndexOf("Intel", beg_)
        end_ = log.IndexOf("]", beg_)
        s = log.Substring(beg_, end_ - beg_ + 1)
        CheckCompiler = s
    End Function
    Function SetCmplrForPlatform(ByVal plNm As String, ByVal vers As String) As Boolean
        Dim pl As VFPlatform
        Dim cll As IVFCollection
        Dim cvs As IVFCollection
        Dim cv As VFFortranCompilerVersion
        Dim maj As String
        Dim min As String
        Dim ind As Integer
        Try
            ind = vers.IndexOf(".")
            maj = vers.Substring(0, ind)
            min = vers.Substring(ind + 1)
            cll = VFPrj.Platforms
            pl = cll.Item(plNm)
            If pl Is Nothing Then
                MsgBox("Platform " + plNm + " not exist")
                Exit Function
            End If
            cvs = pl.FortranCompilerVersions
            Dim j As Integer
            For j = 1 To cvs.Count
                cv = cvs.Item(j)
                If cv.MajorVersion.ToString() = maj And cv.MinorVersion.ToString() = min Then
                    pl.SelectedFortranCompilerVersion = cv
                    SetCmplrForPlatform = True
                    Exit Function
                End If
            Next
            MsgBox("Compiler version " + maj + "." + min + " not exist for platform " + plNm)
            SetCmplrForPlatform = False
        Catch ex As Exception
            SetCmplrForPlatform = False
        End Try
    End Function
    Function getSupportedPlatforms() As ArrayList
        Dim list As ArrayList = New ArrayList()
        Dim pl As VFPlatform
        Dim pls As IVFCollection
        pls = VFPrj.Platforms
        Dim i As Integer
        For i = 1 To pls.Count
            pl = pls.Item(i)
            list.Add(pl.Name)
        Next
        getSupportedPlatforms = list
    End Function
    Function getCompilers(ByVal plNm As String) As ArrayList
        Dim list As ArrayList = New ArrayList()
        Dim pl As VFPlatform
        Dim pls As IVFCollection
        Dim cvs As IVFCollection
        Dim cv As VFFortranCompilerVersion
        Dim j As Integer
        pls = VFPrj.Platforms
        pl = pls.Item(plNm)
        cvs = pl.FortranCompilerVersions
        For j = 1 To cvs.Count
            cv = cvs.Item(j)
            list.Add(cv.DisplayName)
        Next
        getCompilers = list
    End Function
    Function getCompilerVersions(ByVal plNm As String) As ArrayList
        Dim list As ArrayList = New ArrayList()
        Dim pl As VFPlatform
        Dim pls As IVFCollection
        Dim cvs As IVFCollection
        Dim cv As VFFortranCompilerVersion
        pls = VFPrj.Platforms
        pl = pls.Item(plNm)
        cvs = pl.FortranCompilerVersions
        Dim j As Integer
        For j = 1 To cvs.Count
            cv = cvs.Item(j)
            Dim vers As String
            vers = cv.MajorVersion.ToString() + "." + cv.MinorVersion.ToString()
            list.Add(vers)
        Next
        getCompilerVersions = list
    End Function
    Sub printCompilers(ByVal plNm As String, ByVal list As ArrayList)
        Dim s As String
        s = "Platform " + plNm + Chr(13)
        Dim i As Integer
        For i = 0 To list.Count - 1
            s += "   " + list.Item(i) + Chr(13)
        Next
        MsgBox(s)
    End Sub
    Sub addConfiguration(ByVal cfgNm As String)
        Dim cM As ConfigurationManager
        cM = Prj.ConfigurationManager
        cM.AddPlatform(cfgNm, "Win32", True)
    End Sub
    Function getAllConfigurations() As ArrayList
        Dim list As ArrayList = New ArrayList()
        Dim cM As ConfigurationManager
        Dim i As Integer
        Dim c As Configuration
        cM = Prj.ConfigurationManager
        For i = 1 To cM.Count
            c = cM.Item(i)
            list.Add(c.ConfigurationName + "|" + c.PlatformName)
        Next
        getAllConfigurations = list
    End Function
    Sub setActiveCfg(ByVal pNm As String)
        Dim scs As SolutionConfigurations = DTE.Solution.SolutionBuild.SolutionConfigurations
        Dim i As Integer
        Dim j As Integer
        For i = 1 To scs.Count
            Dim sc As SolutionConfiguration
            Dim sctxs As SolutionContexts
            sc = scs.Item(i)
            sctxs = sc.SolutionContexts
            For j = 1 To sctxs.Count
                Dim sctx As SolutionContext = sctxs.Item(j)
                If sctx.ConfigurationName = "Debug" And sctx.PlatformName = pNm Then
                    sc.Activate()
                    Exit Sub
                End If
            Next
        Next
    End Sub
    Sub SolutionRebuild()
        DTE.Solution.SolutionBuild.Clean(True)
        DTE.Solution.SolutionBuild.Build(True)
    End Sub
End Module