- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen the samples in the forum that show how to pass an array of strings from a VB6 COM component to Fortran. But I have not seen one that shows how to pass the array from Fortran to a VB6 COM component. I have done some experimenting declaring a safearray of BSTRs in Fortran and then passing that on to the COM method. After the call, I do get the first few elements of the array populated correctly from the COM method. However, it crashes mid way through the array when I try to access the array elements, so I must be declaring/dimensioning something incorrectly.
Does anyone know if there are examples of this available? Or perhaps describe the basic technique?
Thanks
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It would help if you'd post your code so someone can perhaps spot the problem. Also it's possible to send arrays of strings etc to VB6 using the Win API without incurring the overhead of COM but you're probably aware of that.
Gerry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks a lot for the suggestion. I created a trimmed down version to post and in the process switched to use the interface COM method rather than Automation and it worked! The remaining item I need to figure out is how use the SafeArrayAccessData method to grab the array. The SafeArrayGetElement() method I used is much slower. Calling SafeArrayAccessData and SafeArrayUnaccessDatais straightforward, but I have no idea how to declare an array of character strings to use for mapping to the safearray (i.e., the variable I need to passas SafeArrayAccessData second argument). If anyone has any thoughts on this, it would be greatly appreciated.
My sample that uses the SafeArrayGetElement() method is below.
Thanks, Craig
PROGRAM ArraySample
USE DFLIB
USE DFWIN
USE DFCOM
USE DFCOMTY
USE DFAUTO
USE ArrayTest
IMPLICIT NONE
logical*2 ReturnStatus
integer*4 COMStatus, result, length, i
integer*4 ArraySize
integer*4 ArrayTestObj
integer*4 saArray
character*100 Value
type(sa_bounds), dimension(1) :: saArrayBounds
type(variant) bstrValue
CALL VariantInit(bstrValue)
! Create array test COM object
CALL COMINITIALIZE(COMStatus)
CALL COMCREATEOBJECTBYGUID (CLSID_ArrayTest, CLSCTX_INPROC_SERVER, IID__ArrayTest, ArrayTestObj, COMStatus)
! Get size of array so we can dimension safearray
COMStatus = $$ArrayTest_GetArraySize(ArrayTestObj, ArraySize)
saArrayBounds(1)%extent = ArraySize
saArrayBounds(1)%lbound = 1
! Create the safe array of BSTRs
saArray = SafeArrayCreate(VT_BSTR, 1, saArrayBounds(1))
! Call COM method to get filled array
COMStatus = $$ArrayTest_GetArray(ArrayTestObj, saArray, ReturnStatus)
! Display array elements
do i = 0, ArraySize - 1
result = SafeArrayGetElement(saArray, i, LOC(bstrValue%VU%PTR_VAL))
length = ConvertBSTRToString(bstrValue%VU%PTR_VAL, Value)
write (*, '(A)')Value
read *
end do
CALL COMUNINITIALIZE()
end program

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