Intel® Fortran Compiler 16.0 User and Reference Guide
This topic only applies to Windows* operating systems.
Although Standard Fortran does not support objects, it does provide Standard Fortran modules. A module is a set of declarations that are grouped together under a global name, and are made available to other program units by using the USE statement.
The Intel® Fortran Module Wizard generates a source file containing one or more modules. The types of information placed in the modules include:
Derived-type definitions are Fortran equivalents of data structures that are found in the type information.
Constant definitions are Fortran PARAMETER declarations that include identifiers and enumerations found in the type information.
Procedure interface definitions are Fortran interface blocks that describe the procedures found in the type information.
Procedure definitions are Fortran functions and subroutines that are jacket routines for the procedures found in the type information.
The jacket routines make the external procedures easier to call from Fortran by handling data conversion and low-level invocation details.
The use of modules allows the Intel® Fortran Module Wizard to encapsulate the data structures and procedures exposed by an object or DLL in a single place. You can then share these definitions in multiple Fortran programs.
The appropriate USE statement needs to be added in your program, as well as function invocations or subroutine calls.
The routines generated by the Intel® Fortran Module Wizard are designed to be called from Fortran. These routines in turn call the appropriate system routines (not designed to be called from Fortran), thereby simplifying the coding needed to use COM and Automation objects.
Intel® Visual Fortran provides a set of run-time routines that present to the Fortran programmer a higher level abstraction of the COM and Automation functionality. The Fortran interfaces that the wizard generates hide most of the differences between Automation objects and COM objects.
Depending on the options specified, the following routines can be present in the generated code:
IFCOM Routines (COMxxxxx) |
|
---|---|
Adds a reference to an object's interface. |
|
Passes a programmatic identifier and returns the corresponding class identifier. |
|
Passes a class identifier string and returns the corresponding class identifier. |
|
A generic routine that executes either COMCreateObjectByProgID or COMCreateObjectByGUID. |
|
Passes a class identifier and creates an instance of an object. It returns a pointer to the object's interface. |
|
Passes a programmatic identifier and creates an instance of an object. It returns a pointer to the object's IDispatch interface. |
|
Pass a class identifier and returns a pointer to the interface of a currently active object. |
|
Passes a programmatic identifier and returns a pointer to the IDispatch interface of a currently active object. |
|
Initializes the COM library. You must initialize the library before calling any other COM or AUTO routine. |
|
Determines if two GUIDs are the same. |
|
Passes a file name and returns a pointer to the IDispatch interface of an Automation object that can manipulate the file. |
|
Passes an interface identifier and it returns a pointer to an object's interface. |
|
Indicates that the program is done with a reference to an object's interface. |
|
Passes a GUID and returns the corresponding string representation. |
|
Uninitializes the COM library. This must be the last COM routine that you call. |
IFAUTO Automation Routines (AUTOxxxxx) |
|
---|---|
Passes an argument name and value and adds the argument to the argument list data structure. |
|
Allocates an argument list data structure that holds the arguments that you will pass to AUTOInvoke. |
|
Deallocates an argument list data structure. |
|
Retrieves the exception information when a method has returned an exception status. |
|
Passes the name or identifier of the property and gets the value of the Automation object's property. |
|
Passes the member ID of the property and gets the value of the Automation object's property into the argument list's first argument. |
|
Passes an argument list data structure and gets the value of the Automation object's property specified in the argument list's first argument. |
|
Passes the name or identifier of an object's method and an argument list data structure. It invokes the method with the passed arguments. |
|
Passes the name or identifier of the property and a value. It sets the value of the Automation object's property. |
|
Passes the member ID of the property and sets the value of the Automation object's property using the argument list's first argument. |
|
Passes an argument list data structure and sets the value of the Automation object's property specified in the argument list's first argument. |
The following code shows an annotated version of a portion of the code generated by the Intel® Fortran Module Wizard. This code is generated from the COM type information for the Save method of the IGeneric Document interface.
INTERFACE ! Saves the document to disk. 1 INTEGER*4 FUNCTION IGenericDocument_Save($OBJECT, vFilename, & vBoolPrompt, pSaved) 2 USE IFWINTY INTEGER (INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer !DIR$ ATTRIBUTES VALUE :: $OBJECT 3 TYPE (VARIANT), INTENT(IN), OPTIONAL :: vFilename ! (Optional Arg) 4 !DIR$ ATTRIBUTES REFERENCE :: vFilename TYPE (VARIANT), INTENT(IN), OPTIONAL :: vBoolPrompt ! (Optional Arg) !DIR$ ATTRIBUTES REFERENCE :: vBoolPrompt INTEGER, INTENT(OUT) :: pSaved ! DsSaveStatus 5 !DIR$ ATTRIBUTES REFERENCE :: pSaved !DIR$ ATTRIBUTES STDCALL :: IGenericDocument_Save END FUNCTION IGenericDocument_Save END INTERFACE POINTER(IGenericDocument_Save_PTR, IGenericDocument_Save) ! routine pointer 6
Notes for this example:
1 If the type information provides a comment that describes the member function, then the comment is placed before the beginning of the procedure.
2 The first argument to the procedure is always $OBJECT. It is a pointer to the object's interface. The remaining argument names are determined from the type information. For information on how to get a pointer to an object's interface, see Getting a Pointer to an Objects Interface.
3 This is an example of an ATTRIBUTES directive statement used to specify the calling convention of an argument.
4 A VARIANT is a data structure that can contain any type of Automation data. It contains a field that identifies the type of data and a union that holds the data value. The use of a VARIANT argument allows the caller to use any data type that can be converted into the data type expected by the member function.
5 Nearly every COM member function returns a status of type HRESULT. Because of this, if a COM member function produces output, it uses output arguments to return the values. In this example, the "pSaved" argument returns a routine specific status value.
6 The interface of a COM member function looks very similar to the interface for a dynamic link library function with one major exception. Unlike a DLL function, the address of a COM member function is never known at program link time. You must get a pointer to an object's interface at run-time, and the address of a particular member function is computed from that.
The following code shows an annotated version of the wrapper generated by the Intel® Fortran Module Wizard for the "Save" function. The name of a wrapper is the same as the name of the corresponding member function, prefixed with a "$" character.
! Saves the document to disk. INTEGER*4 FUNCTION $IGenericDocument_Save($OBJECT, vFilename, & 1 vBoolPrompt, pSaved) IMPLICIT NONE INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer !DIR$ ATTRIBUTES VALUE :: $OBJECT TYPE (VARIANT), INTENT(IN), OPTIONAL :: vFilename !DIR$ ATTRIBUTES REFERENCE :: vFilename TYPE (VARIANT), INTENT(IN), OPTIONAL :: vBoolPrompt !DIR$ ATTRIBUTES REFERENCE :: vBoolPrompt INTEGER, INTENT(OUT) :: pSaved ! DsSaveStatus !DIR$ ATTRIBUTES REFERENCE :: pSaved INTEGER(4) $RETURN INTEGER(INT_PTR_KIND()) $VTBL ! Interface Function Table 2 POINTER($VPTR, $VTBL) TYPE (VARIANT) :: $VAR_vFilename TYPE (VARIANT) :: $VAR_vBoolPrompt IF (PRESENT(vFilename)) THEN 3 $VAR_vFilename = vFilename ELSE $VAR_vFilename = OPTIONAL_VARIANT END IF IF (PRESENT(vBoolPrompt)) THEN $VAR_vBoolPrompt = vBoolPrompt ELSE $VAR_vBoolPrompt = OPTIONAL_VARIANT END IF $VPTR = $OBJECT ! Interface Function Table 4 $VPTR = $VTBL + 84 ! Add routine table offset IGenericDocument_Save_PTR = $VTBL $RETURN = IGenericDocument_Save($OBJECT, $VAR_vFilename, & $VAR_vBoolPrompt, pSaved) $IGenericDocument_Save = $RETURN END FUNCTION $IGenericDocument_Save
Notes for this example:
1 The wrapper takes the same argument names as the member function interface.
2 The wrapper computes the address of the member function from the interface pointer and an offset found in the interface's type information. In implementation terms, an interface pointer is a pointer to a pointer to an array of function pointers called an "Interface Function Table."
3 Arguments to a COM or Automation routine can be optional. The wrapper handles the invocation details for specifying an optional argument that is not present in the call.
4 The offset of the "Save" member function is 84. The code assigns the computed address to the function pointer IGenericDocument_Save_PTR, which was declared with the interface shown above, and then calls the function.
The following code shows an annotated version of a portion of the code generated by the Intel® Fortran Module Wizard from Automation type information for the Rebuild All method of the IApplication interface.
! Rebuilds all files in a specified configuration. SUBROUTINE IApplication_RebuildAll($OBJECT, Configuration, $STATUS) 1 IMPLICIT NONE INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer !DIR$ ATTRIBUTES VALUE :: $OBJECT TYPE (VARIANT), INTENT(IN), OPTIONAL :: Configuration !DIR$ ATTRIBUTES REFERENCE :: Configuration INTEGER(4), INTENT(OUT), OPTIONAL :: $STATUS ! Method status !DIR$ ATTRIBUTES REFERENCE :: $STATUS INTEGER(4) $$STATUS INTEGER (INT_PTR_KIND) invokeargs invokeargs = AUTOALLOCATEINVOKEARGS() 2 IF (PRESENT(Configuration)) CALL AUTOADDARG(invokeargs, '$ARG1', & Configuration, AUTO_ARG_IN) $$STATUS = AUTOINVOKE($OBJECT, 28, invokeargs) 3 IF (PRESENT($STATUS)) $STATUS = $$STATUS 4 CALL AUTODEALLOCATEINVOKEARGS (invokeargs) 5 END SUBROUTINE IApplication_RebuildAll
Notes for this example:
1The first argument to the procedure is always $OBJECT. It is a pointer to an Automation object's IDispatch interface. The last argument to the procedure is always $STATUS. It is an optional argument that you can specify if you wish to examine the return status of the method. The IDispatch Invoke member function returns a status of type HRESULT. An HRESULT is a 32-bit value. It has the same structure as a Windows error code. In between the $OBJECT and $STATUS arguments are the method arguments' names determined from the type information. Sometimes, the type information does not provide a name for an argument. The Fortran Module Wizard creates a "$ARGn" name in this case.
2 AUTOAllocateInvokeArgs allocates a data structure that is used to collect the arguments that you will pass to the method. AUTOAddArg adds an argument to this data structure.
3 AUTOInvoke invokes the named method passing the argument list. This returns a status result.
4 If the caller supplied a status argument, the code copies the status result to it.
5AUTODeallocateInvokeArgs deallocates the memory used by the argument list data structure.