Calling COM from Intel Fortran?

Posted by user57460 on Programmers See other posts from Programmers or by user57460
Published on 2012-06-22T23:12:11Z Indexed on 2012/06/23 3:23 UTC
Read the original article Hit count: 301

Filed under:
|

I'm trying to get COM working from my Fortran application. I do a "COMINITIALIZE" followed by a "COMCreateObjectByProgID". Both of these appear to be successful and return a status of zero. However, when I try to use the COM object, I get "Unhandled exception at 0x00000000 in FortranProg01.exe: 0xC0000005: Access violation."

I realize that this error can mean almost anything, but has anyone got some suggestions of common problems with COM that produce this problem?

Here are some more details. My program code:

program FortranProg01

use myolepg
implicit none

integer*4 comInitStatus
integer:: comCreateStatus
INTEGER(INT_PTR_KIND()) $OBJECT
INTEGER(4) funcResult
REAL(8) pkgVersion

call COMINITIALIZE(comInitStatus)
print *, comInitStatus

call COMCreateObjectByProgID('MyOlePg.MyOlePkg', $OBJECT, comCreateStatus)
print *, comCreateStatus

funcResult = IMyOlePkg_GetPackageVersion($OBJECT, pkgVersion)
print *, funcResult

call COMUNINITIALIZE()

end program FortranProg01

The wizard-generated interface code:

INTERFACE

  !property PackageVersion

    INTEGER(4) FUNCTION IMyOlePkg_GetPackageVersion($OBJECT, pVal)

    INTEGER(INT_PTR_KIND()), INTENT(IN) :: $OBJECT ! Object Pointer

    !DEC$ ATTRIBUTES VALUE :: $OBJECT

    REAL(8), INTENT(OUT) :: pVal 

    !DEC$ ATTRIBUTES REFERENCE :: pVal

  !DEC$ ATTRIBUTES STDCALL :: IMyOlePkg_GetPackageVersion

  END FUNCTION IMyOlePkg_GetPackageVersion

END INTERFACE

Any help would be much appreciated!

Thanks! Brad.

© Programmers or respective owner

Related posts about fortran

Related posts about com