Software Archive
Read-only legacy content
17061 Discussions

Passing a safearray using a variant

dmor
Beginner
1,698 Views
How do I pass a safearray into a COM object using a variant? In C++ there is a variant type VT_ARRAY. What does CVF use? Is there an example?

Thanks

Dave
www.unit-conversion.com
0 Kudos
5 Replies
Intel_C_Intel
Employee
1,698 Views
Hi,

VARIANTs and SafeArrays are Windows (COM) concepts and are documented in the Microsoft documentation. VF doesn't provide any additional abstraction over these native Windows types. We merely try to provide Fortran interfaces and type definitions for the Windows functionality. There are a few examples of using SafeArrays and VARIANTs in the ...SamplesAdvancedCOM directory. VT_ARRAY (and friends) are defined in the DFWINTY module with the same values as in the VC++ header files.

Many of the problems that people encounter in dealing with VF COM clients/servers have to do with the mostly undocumented restrictions in Visual Basic. It demands that arguments be passed in particular ways - it will not accept any legal VARIANT that you can create, for example. See "Interface Design Considerations" in the "Creating a COM Server" chapter for an example of VB restrictions.

Leo
0 Kudos
dmor
Beginner
1,698 Views
Hi Lea

Thanks for the reply. I do understand what safe arrays and variants are.

I've built a OM server that expects a safe array passed inside a variant for one of its methods. One of my clients is trying to call this method from CVF. He has managed to create and populate a safe array but is unable to attach it to a variant. In I++ the TV_TYPE would be TV_R8 | TV_ARRAY and the pArray member would be set to the address of the safearray. I suspect he should use

variant%VT = ior(VT_ARRAY,VT_R8)

to set the type, but I'm not sure about the pArray member.

Help!

Dave
0 Kudos
dmor
Beginner
1,698 Views
Sorry Leo, the spellchecker attacked my posting! I'm guessing that I need to provide a value for PTR_VAL. What do I give it? The value returned from the safe array creation is a handle.

Dave
0 Kudos
Intel_C_Intel
Employee
1,698 Views
> Sorry Leo, the spellchecker attacked my posting! I'm guessing that I need to provide a value for PTR_VAL. What do I give it? The value returned from the safe array creation is a handle.

Yes, you do assign the value returned by safe array creation to PTR_VAL. The handle is a SAFEARRAY* which is a pointer to a data structure (descriptor) that describes the array and is exactly what you need to pass.

If you are still having problems, set a breakpoint in your server in the "interfacename".f90 file in the "Do Not Edit" folder. The functions that follow the "Wrapper functions called from the Vtbl" are where the method calls enter your server. There, you can see exactly what is being passed by the client.

Leo
0 Kudos
dmor
Beginner
1,698 Views
Success! My safearray and variant was creation. However my COM method was doing some bizarre things, which I've now corrected. Thanks for the help.

Dave
0 Kudos
Reply