G'day everyone
Context: Compaq Visual Fortran 6.6c on Windows XP Professional
I'm trying to work out how to convert a BSTR to an array of INTEGER*2.
The current code is as follows. First, the COM object routine which is
receiving an array of variants.
function IArraySort_Sort1DVariantArray( ObjectData ,&
aArray,&
nDirection) result (hresult)
use ArraySort_Types
USE DFAXT
USE DFLIB
implicit none
type(ArraySort_InstanceData) ObjectData
!dec$ attributes reference :: ObjectData
TYPE(VARIANT), intent(inout) :: aArray
DIMENSION aArray(1:)
INTEGER(4), intent(in) :: nDirection
integer(LONG) hresult
! TODO: Add implementation
INTEGER*4 :: nArrayLength
INTEGER*4 :: nArrayElementSize
nArrayLength = SIZE(aArray)
nArrayElementSize = 16
CALL QSORT(aArray,nArrayLength,nArrayElementSize,cmp_function)
IF (nDirection .EQ. -1) THEN
aArray = reverseV(aArray)
ENDIF
hresult = S_OK
end function
Next, the code used by QSORT to setup up for a VARIANT comparison and to
do the comparison
interface qsort
subroutine qsort_typevariant( array, len, isize, compar )
!DEC$ ATTRIBUTES alias:'_QSORT@16' :: qsort_typevariant
use portlib
use dfwinty
type(VARIANT) array(*)
integer len, isize
integer(2), external :: compar
end subroutine
end interface
function cmp_function(a1, a2)
USE DFWINTY
USE DFCOM
INTEGER*2 :: cmp_function
TYPE(VARIANT) :: a1, a2
CHARACTER(LEN=256) :: b1, b2
CALL ConvertBSTRToString( a1%VU%PTR_VAL, b1)
CALL ConvertBSTRToString( a2%VU%PTR_VAL, b2)
IF (b1 .LT. b2) THEN
cmp_function = -1
ELSE
cmp_function = 1
ENDIF
end function
If the strings are in UTF8 the sort handles the fact that I'm sending in
Chinese. If the strings are in UTF16, ConvertBSTRToString turns the
characters into question marks, so the compare is comparing question
marks with question marks.
Now I have thought about preconverting all the input data from UTF16 to
UTF8 and then postconverting it all back to UTF16 after the sort.
However, it'd be really nice if I could keep it all in UTF16. So what
I'm asking for is this: how to I convert a BSTR to an array of
INTEGER*2? That way I wouldn't have to pre/post convert to/from UTF8 and
would have a comparison that didn't fall back to question marks when
processing Chinese.
Any ideas?
Kind regards,
Bruce M. Axtens
Software Engineer
The Protium Project
[Non-text portions of this message have been removed]