SafeArrayCopy
f90VB Modules
f90VBDefs, f90VBSafeArrays
Summary
Creates a copy of an existing Safe Array.
Syntax
| subroutine SafeArrayCopy | (SARefSrc, SARefDest, iRet) |
| { | |
| integer(SAFEARRAY_KIND),intent(in):: | SARefSrc | |
| type(FSafeArray),intent(in):: | SARefSrc | |
| } | |
| { | |
| integer(SAFEARRAY_KIND),intent(out):: | SARefDest | |
| type(FSafeArray),intent(out):: | SARefDest | |
| } | |
| integer(HRESULT_KIND),intent(out),optional:: | iRet |
Arguments
SARefSrc [Input]
A handle to, or a Fortran Safe Array structure containing a handle to, the Safe Array to be copied.
SARefDest [Output]
A handle to, or a Fortran Safe Array structure containing a handle to, a new Safe Array that is a copy of SARefSrc.
iRet [Output/Optional]
Upon return, iRet contains S_OK or an error code. See comments for more information.
Comments
SafeArrayCopy calls the string or variant manipulation functions if the array to copy contains either of these data types. If the array being copied contains object references, the reference counts for the objects are incremented.
Argument iRet
Indicates success or failure of the subroutine. The following codes can be returned in this argument:
| Value returned in argument iRet | Description | |
| S_OK | Success. | |
| E_INVALIDARG | One of the arguments is invalid. | |
| E_OUTOFMEMORY | Memory for the new Safe Array could not be allocated. | |
Examples
| program SafeArrayCopyExamples |
!Demonstrates the use of subroutine SafeArrayCopy
!Copyright 1999-2000, Canaima Software
!All rights reserved
use f90VBDefs
use f90VBSafeArrays
use f90VBBstrings
integer(SAFEARRAY_KIND)::SAHndlA, SAHndlB
type(FSafeArray)::FSA_A, FSA_B
integer(HRESULT_KIND)::iRet
integer(BSTRHNDL_KIND),pointer::MapArray(:)
integer(LONG_KIND)::i
character(len=15)::iStr
!Create a Safe Array vector with 3 elements
call SafeArrayCreate(SAHndlA,VT_BSTR,1,3)
!Map a Fortran array to this safe array
call SafeArrayAccessData(SAHndlA,MapArray,iRet)
!Fill SAHndl with three strings using the mapped
!fortran array
do i=1,3
write(iStr,'(i2.2)') i
MapArray(i)=BStrAlloc('String_' // trim(iStr))
enddo
!copy Safe Array SAHndlA to FSA_A
call SafeArrayCopy(SAHndlA,FSA_A)
!copy Safe Array FSA_A to FSA_B
call SafeArrayCopy(FSA_A,FSA_B)
!copy Safe Array FSA_B to SAHndlB
call SafeArrayCopy(FSA_B,SAHndlB)
!Print the handles of the BStrings in the four
!arrays, showing that they are all different
!but their content is the same
print *,'BString handles and content in Safe Array SAHndlA:'
do i=1,3
call StrCopy(MapArray(i),iStr)
write(*,'(a1,i1,a10,i7,3x,a8,a15)') '(',i,'): Handle:', &
MapArray(i),'Content:',trim(iStr)
enddo
call SafeArrayAccessData(SAHndlB,MapArray,iRet)
print *,''
print *,'BString handles and content in Safe Array SAHndlB:'
print *, (MapArray(i),i=1,3)
do i=1,3
call StrCopy(MapArray(i),iStr)
write(*,'(a1,i1,a10,i7,3x,a8,a15)') '(',i,'): Handle:', &
MapArray(i),'Content:',trim(iStr)
enddo
call SafeArrayAccessData(FSA_A,MapArray,iRet)
print *,''
print *,'BString handles and content in Safe Array FSA_A:'
print *, (MapArray(i),i=1,3)
do i=1,3
call StrCopy(MapArray(i),iStr)
write(*,'(a1,i1,a10,i7,3x,a8,a15)') '(',i,'): Handle:', &
MapArray(i),'Content:',trim(iStr)
enddo
call SafeArrayAccessData(FSA_B,MapArray,iRet)
print *,''
print *,'BString handles and content in Safe Array FSA_B:'
print *, (MapArray(i),i=1,3)
do i=1,3
call StrCopy(MapArray(i),iStr)
write(*,'(a1,i1,a10,i7,3x,a8,a15)') '(',i,'): Handle:', &
MapArray(i),'Content:',trim(iStr)
enddo
!Destroy all the safe arrays and their content
call SafeArrayDestroy(SAHndlA)
call SafeArrayDestroy(SAHndlB)
call SafeArrayDestroy(FSA_A)
call SafeArrayDestroy(FSA_B)
stop
end
Related Topics
| For information about: | See: | |
| Creating a Safe Array | SafeArrayCreate | |