- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Thanks
Dave
www.unit-conversion.com
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Dave
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
> 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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Dave

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page