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

Retrieving variant from pointer to variant in Automation

alb_f
Novice
436 Views

I have an automation server (64 bit dll with callable method) with a client in IVF. The client's interface was created using the Intel Visual Fortran Module Wizard and runs in 32 bit mode. Using the information from the Compaq Visual Fortran Programmers Guide on Automation/COM I managed to get things working in so far that my client calls the server, returning success.

The server now simply returns two integer values and I have to find out how to retrieve these values in my client. Though there is some information on the internet, largely for the C languages, I cannot find how to do this in Fortran. 

My automation interface is like this (output arguments fa1, fa2)

SUBROUTINE IClassCOMsrv_COMsrv($OBJECT, nargout, fa1, fa2, a1, a2, a3, $STATUS)
!DEC$ ATTRIBUTES DLLEXPORT :: IClassCOMsrv_COMsrv
IMPLICIT NONE

INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer
!DEC$ ATTRIBUTES VALUE :: $OBJECT
INTEGER(4), INTENT(IN) :: nargout
!DEC$ ATTRIBUTES REFERENCE :: nargout
TYPE (VARIANT), INTENT(INOUT), VOLATILE :: fa1
!DEC$ ATTRIBUTES REFERENCE :: fa1
TYPE (VARIANT), INTENT(INOUT), VOLATILE :: fa2
!DEC$ ATTRIBUTES REFERENCE :: fa2
TYPE (VARIANT), INTENT(IN) :: a1
!DEC$ ATTRIBUTES REFERENCE :: a1
TYPE (VARIANT), INTENT(IN) :: a2
!DEC$ ATTRIBUTES REFERENCE :: a2
TYPE (VARIANT), INTENT(IN) :: a3
!DEC$ ATTRIBUTES REFERENCE :: a3
INTEGER(4), INTENT(OUT), OPTIONAL :: $STATUS ! Method status
!DEC$ ATTRIBUTES REFERENCE :: $STATUS
 
The calling routine is:
Call IClassCOMsrv_COMsrv(matlab_app, nargout, vfa1, vfa2, va1, va2, va3, status)

 

where input arguments va1, va2, va3 are properly initialized as variants of type VT_I4 and value  VU%LONG_VAL and  vfa1 and vfa2 are declared as variants.

This routine returns status == 0 and I can hear (generated system beep by dll method) it called the dll method.
Now the returned vfa1 and vfa2 are variants with type v%VT = 16396 which equals a 
VT_BYREF | VT_VARIANT type.
 
alb_f_0-1617263449234.jpeg

 

From the information I got this type could be dereferenced using a call like 
result = VariantCopyInd( pv, v )
where pv then should be the dereferenced variant. However, this routine returns an error value in result (-2147024809) meaning hex code 0x80070057 or E_INVALIDARG (One or more arguments are invalid) and the resulting variant pv just has the initial zeroed values in it.
 
How do I properly in Fortran dereference such a variant type to obtain the returned integer value again? Is the mentioned error due to the fact that my dll method is 64 bit while my client is 32 bit? And is there any good information on COM/Automation with IVF including example code?
0 Kudos
1 Reply
Steve_Lionel
Honored Contributor III
391 Views

There is very little expertise available on using COM from Fortran.  There's one sample provided, but it likely doesn't help you.

Do you know what the value should be? Might it be as simple as referencing VFA1%VU%LONG_VAL?

0 Kudos
Reply