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

COM problem: access violation

pletzky
Beginner
569 Views
Whereas I posted this at the end of a different thread, I think it deserves its own posting.

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 andreturn 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


Thanks!
Brad.

0 Kudos
4 Replies
SergeyKostrov
Valued Contributor II
569 Views
1. You could try tocall a 'CoCreateInstance' COM-function instead.

2. Did you try to create an instance of your COM-object with a simple Visual Basic or .NET application?

Best regards,
Sergey
0 Kudos
pletzky
Beginner
569 Views
Thank-you so much for your reply! Unfortunately,
1. I have no idea how to use CoCreateInstance in Fortran, and have been unable to find an example.
2. It works perfectly from a .NET application.

Brad.
0 Kudos
pletzky
Beginner
569 Views
OK, it looks like this was a package-specific problem. More accurately, it was my misunderstanding either of the package or of current Fortran conventions. As far as I can tell, pretty much all of the methods in the package are defined twice, once with a regular name and once with a "$" preface. So, if I use the "$IMyOlePkg_GetPackageVersion" call instead of the "IMyOlePkg_GetPackageVersion" call, I get a build warning ("ipo: warning #11077: ...: locally defined symbol ... imported", but it WORKS! (What's particularly interesting is that the "$" method appears simply to add an offset and then call the "non-$" method.)

Now whereas I don't really like the warning, and I'd be happy if someone could explain both the warning and the two different calls, I have it working, and if I never get a satisfactoryexplanation, I can probably learn to live with that.

Thanks!
Brad.
0 Kudos
SergeyKostrov
Valued Contributor II
569 Views
Quoting pletzky
...I get a build warning ("ipo: warning #11077: ...: locally defined symbol ... imported", but it WORKS! (What's particularly interesting is that the "$" method appears simply to add an offset and then call the "non-$" method.)

Now whereas I don't really like the warning, and I'd be happy if someone could explain both the warning and the two different calls, I have it working, and if I never get a satisfactoryexplanation, I
can probably learn to live with that.

Hi Brad,
This is only a warning and ifapplication works,results/outputs are consistent, I would say, the problem is solved.
Best regards,
Sergey
0 Kudos
Reply