Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28996 Discussions

newbie: problem with array of VARIANT and TRANSFORM

axtens
Beginner
381 Views
G'day everyone

Using CVF 6.6 under Windows XP Pro:

I'm writing a COM DLL. I have two 2D allocatable arrays of VARIANT. In one routine, I
load data into the first array as VT_BSTRs using SysAllocStringLen. In another routine,
I TRANSPOSE that array into the second 2D array. In a third routine, I store the
contents of the second array into a safearray for passing back to the caller.

The problem I have is that TRANSPOSE seems to mangle the destination array in a weird
way. The addresses that are allocated by SysAllocStringLen do not change (I've checked
that) but what is pointed to appears to change. I know this because when I call
SysStringLen against ... % VU % PTR_VAL, I get a length that is quite different to that
of the original. What is even more perverse is that some lengths are correct and some
are not.

Below is debug output as the source code is now quite lengthy and involved (though I'm
quite happy to send it to you off-list):

First part (after the [3548] bit) is column, row, address of BSTR, and number of
characters. This is what's in the first 2D variant array.
[3548] 1 1 1652940 2
[3548] 2 1 1652900 2
[3548] 3 1 1652980 2
[3548] 4 1 1654156 2
[3548] 1 2 1653020 2
[3548] 2 2 1653060 2
[3548] 3 2 1698932 2
[3548] 4 2 1764756 2
[3548] 1 3 2230836 2
[3548] 2 3 1698908 2
[3548] 3 3 1698884 2
[3548] 4 3 1698860 2

First part (after the [3548] bit) is column, row, address of BSTR, and number of
characters. This is the second 2D array after having TRANSPOSEd the first array into it.
[3548] 1 1 1652940 2
[3548] 1 2 1652900 2
[3548] 1 3 1652980 2
[3548] 1 4 1654156 2
[3548] 2 1 1653020 2
[3548] 2 2 1653060 2
[3548] 2 3 1698932 1115416

What I don't understand is why the string at 1698932 is now 115416 characters long when
it was 2 characters only milliseconds before. BTW, there are no values after this
because it's at this point the program crashes.

I'm at a loss to figure out what is happening. Any ideas?

Kind regards,
Bruce.

P.S. Cross-posted in comp.lang.fortran
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
381 Views
Well, your questions in clf aren't exactly "newbie's" ones... smiley [:-)]

You seem to be corrupting memory somehow somewhere. Without the code, it's difficult to tell.

1) What happens if you replace TRANSPOSE with a plain vanilla double do-loop?
2) If you still cannot figure out what is happening, please send me a complete code at jdujic (at) uns ns ac yu.
0 Kudos
Reply