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

Using SafeArays in Fortran

ripittard
New Contributor I
490 Views

I am trying to decifer a safearray passed from visualbasic.  I can access bounds, individual elements, use a pointer to access arrays "in place" but I cannot seem to get SafeArrayGetVarType to work.  The compiler complains fwhen I try to use SafeArrayGet VarType:

... 

integer(int_ptr_kind()), intent(inout) :: VBArray

Integer iRes, iType

...

iRes = SafeArrayGetVarType(VBArray, iType)

 

 

error #6404: This name does not have a type, and must have an explicit type. [SAFEARRAYGETVARTYPE]

 

it also errors out if I skip assigning the result to iRes adn just "call it" instead.  I have attached the full routine.  Any help would be appreciated. 

Thanks,

Rick

0 Kudos
1 Solution
Steve_Lionel
Black Belt Retired Employee
354 Views

You can write your own interface for that function easily enough. It would probably look like this:

interface
function SafeArrayGetVarType (array, vt) bind(C,name="SafeArrayGetVarType")
!DIR$ ATTRIBUTES STDCALL :: SafeArrayGetVarType
use IFWINTY
integer(HANDLE) :: SafeArrayGetVarType
type(*), intent(in) :: array
integer(SHORT), intent(out) :: vt
end function SafeArrayGetVarType
end interface

 

View solution in original post

4 Replies
Steve_Lionel
Black Belt Retired Employee
470 Views

There is a SafeArrays sample in the Samples Bundle, under compiler_f\MixedLanguages. However, no routine named SafeArrayGetVarType is defined (in module OLEAUT32). I see that Microsoft does define such a routine, with an output argument of VARTYPE, but it seems related to variant types.  It does seem that the returned type is not a simple integer. It would take some research to see just what this was and how to use it.

MWind2
New Contributor III
380 Views

I have not played with this enough to get arrays or complex results that seem available in other methods, but with an array of doubles such returns 5, the underlying datatype:

#include "oaidl.h"
// returns data type in array
extern "C" DCPP_API long VTSafeArray(SAFEARRAY * *psaArray) {
    int iVT;
    VARTYPE VT;  //short
    HRESULT hRes = SafeArrayGetVartype(*psaArray, &VT);
    iVT = (int)VT;
    return iVT;
}

// https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms897140(v=msdn.10)
// https://docs.microsoft.com/en-us/windows/win32/api/oleauto/nf-oleauto-safearraygetvartype

 

Steve_Lionel
Black Belt Retired Employee
355 Views

You can write your own interface for that function easily enough. It would probably look like this:

interface
function SafeArrayGetVarType (array, vt) bind(C,name="SafeArrayGetVarType")
!DIR$ ATTRIBUTES STDCALL :: SafeArrayGetVarType
use IFWINTY
integer(HANDLE) :: SafeArrayGetVarType
type(*), intent(in) :: array
integer(SHORT), intent(out) :: vt
end function SafeArrayGetVarType
end interface

 

ripittard
New Contributor I
331 Views
Reply