Using COM Objects with CVF

Using COM Objects with CVF

I have been updating some FORTRAN code that used Automation Objects (an in process server written in VB)- and had significant difficulty access routines using SafeArrays.
My first attempts used CVF 6.1 and failed. I finally attributed that failure to the lack of the INTENT(INOUT) attribute and updated to 6.6. I still had problems. The SafeArray of Unsigned Integers was defined as CHARACTER, DIMENSION(:), INTENT(INOUT)with the usual !DEC$ ATTRIBUTES REFERENCE in the function of the module the wizard generated. I could not get the compiler to even produce code as it complained of type mismatch.
After consulting some other users of similar ActiveX COM Objects, I convinced the author of this COM Object to make this function return a Variant rather than a SafeArray. Lo and behold, it worked. I have never liked imprecise declarations (yes I always use IMPLICIT NONE) - but have concluded (yet again)that you need to let the system do what the designers intended. Variants seem to let you "get by" with somewhat loose or ill-defined interfaces.

Is this a reasonable conclusion and is there any reason to not use Variants as the preferred type for COM or Automation Work?

Anyone have any samples of accessing COM or Automation Objects from CVF?

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

As far as I can remember there are few examples in the CVF samples directory...AdavancedCOM but you presumably gone through that. Maybe a short arcticle by Leo Treggiari or his second one describing Module Wizard with few code samples and explanations can help.
Moreover, there is nice description in Docs .

SafeArrays and Fortran examples tou can find here .

Artur

Thanks, arturguzik, for reminding me of the two articles.
It's been a while since I had looked at a Digital Technical Journal article, and it aided my understanding of COM. I believe I had followed the examples correctly, but the compiler thought there was a type mismatch. It could be that the COM Server I was accessing was poorly written, or didn't have a reasonable interface defined. Making the parameter in the interface a Variant apparently made passing the data easier. The variant points to a SafeArray and now my code works - I just had to add the line to extract the pointer to the safearray from the variant. What I was getting at with my question, was that using a variant did make it easier to pass data into my FORTRAN COM client. I was curious if others had experienced this and what is the computational cost of the varient. Obviously, I added one de-reference on both the server and the client, but I haven't got enough experience to judge the full repurcussions. Thanks.

Dave,

I'm afraid, I can't assist with your Q. However, maybe this
example code will help. As I understand your problem Variants type variable helps you standard way, I mean you do not need to worry about matching types (it's converted into the data type expected by the caller). Maybe, now I speculate, when you extract your data you assume the type incorrectly or it different or changes between calls.

Artur

Leave a Comment

Please sign in to add a comment. Not a member? Join today