caffeine 0 Newbie Poster

In VBA, I create a 3-D array of doubles of dimension (6, 100, 240). The dimensions of the 3-D array is (0 to 5, 1 to 100, 1 to 240). Here is what a VB watch of the 3-D array looks like:

ir         Variant/Variant(0 to 5)
ir(0)      Variant/Variant(1 to 100, 1 to 240)
ir(0)(1)   Variant(1 to 240)
ir(0)(1,1) Variant/Double

I pass this array to a C++ DLL and it arrives as a VARIANT SAFEARRAY of 6 VARIANT SAFEARRAYs of doubles.

IRScenarios::IRScenarios( VARIANT *vIRArray )
{
	// Make sure we have a VARIANT that contains a SAFEARRAY.
	assert(V_VT(vIRArray) & VT_ARRAY);

	// In VBA, when you assign the Range.Value property to a Variant, it
	// gets passed to C++ as a VARIANT containing a SAFEARRAY of VARIANT arrays.
	assert( (V_VT(vIRArray) & VT_TYPEMASK) == VT_VARIANT );

	// sArray is a 1-D SAFEARRAY of 6 elements.
	// Each element is a 2-D VARIANT array of doubles.
	SAFEARRAY* sArray = V_ARRAY(vIRArray);
	assert( sArray->cDims == 1 );
	assert( sArray->rgsabound->lLbound == 0 );


	long nIRTypes = sArray->rgsabound->cElements;

	for( int irType = 0; irType < nIRTypes; ++irType )
		data.push_back( vector< vector<double> >() );


	LONG bound[2];
	double tempVal = 0.0;

	for( long irType = 0; irType < 6; ++irType )
	{
		// Add a new IR Type.
		data.push_back( vector< vector<double> >() );

		VARIANT v;
		SafeArrayGetElement(sArray, &irType, &v);
		SAFEARRAY *sa = v.parray;
		// SAFEARRAY *sa = V_ARRAY(&v);

		long lScenarioBound, uScenarioBound, lMonthBound, uMonthBound;
		SafeArrayGetLBound(sa, 1, &lScenarioBound);
		SafeArrayGetUBound(sa, 1, &uScenarioBound);
		SafeArrayGetLBound(sa, 2, &lMonthBound);
		SafeArrayGetUBound(sa, 2, &uMonthBound);

		for( int s= lScenarioBound; s<= uScenarioBound; ++s)
		{
			data[irType].push_back( vector<double>() );
			bound[1] = scenario;

			for( int month = lMonthBound; month <= uMonthBound; ++month)
			{
				bound[0] = month;
				SafeArrayGetElement( sa, bound, &tempVal );
				data[irType][s - 1].push_back(tempVal);
			}
		}

	}
}

Everything looks healthy until I go to grab the double value with SafeArrayGetElement. The value placed into tempVal is obviously nonsense.

I've included screenshots of vIRArray, sArray, sa, and tempVal.

Can anyone please help me figure out why is tempVal receiving a bogus value?

Thanks!
Pete