
Passing 2D array between VB And VC++
So? That's exactly what you specified in a call to SafeArrayCreate.
First dimension, aDim[0], 0 to 3 (4 elements total). Second dimension,
aDim[1], 0 to 2 (3 elements total). I don't see any problem there. What
did you expect?
You are playing with terms "column" and "row" and confusing yourself.
Think about "first (leftmost) dimension" and "second (rightmost)
dimension", and you'll find that dimensions in VB and VC coincide
perfectly.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
Quote:
> OK
> Here is the code for VC++ side where I pass a safe array of 0 t0 2 , 0
to 3
> from VB side and I create another array in VC++ and return to VB
> VC++ code
> STDMETHODIMP CTestMacroInterface::ProcessStringArray(SAFEARRAY **
> ppInputArray, SAFEARRAY **ppOutputArray)
> {
> AFX_MANAGE_STATE(AfxGetStaticModuleState())
> HRESULT hresult;
> int ColUBound;
> int RowUBound
> (0-2 x 0-3
> ColUBound=(*ppInputArray)->rgsabound[0].cElements-1; ''2
> RowUBound=(*ppInputArray)->rgsabound[1].cElements-1; ''3
> Now create a same 2D array in VC++ and return
> SAFEARRAYBOUND aDim[2];
> aDim[0].lLbound = 0;
> aDim[0].cElements = 4 ;//
> aDim[1].lLbound = 0;
> aDim[1].cElements =3;//VB Column 3 VC++ Row
> BSTR HUGEP *pbstr;
> *ppOutputArray=SafeArrayCreate(VT_BSTR , 2, aDim);
> if (*ppOutputArray==NULL)
> {
> ::MessageBox(NULL, _T("NOT_OK"), _T("Pickup"), MB_OK);
> }
> else
> {
> }
> return S_OK;
> }
> VB side
> Dim Inputarray(0 To2, 0 To 3) as string
> Dim OutputArray() as string
> obj.ProcessStringArray InputArray , OutputArray
> I am getting (0 to 3 and 0 to 2) instead of 0 to 2 and 0 to 3
> > The problem is in the code you don't show. Show a small sample that
> > reproduces the problem, both on C++ and VB side.
> > --
> > With best wishes,
> > Igor Tandetnik
> > "For every complex problem, there is a solution that is simple,
neat,
> > and wrong." H.L. Mencken
> > > Hi every one
> > > I defined a 2D String array (0 to2 , 0 to 3) and pass to VC++.
> > > In VC++ it was translated as (0 to 3 and 0 to 2) (Transposed)
> > > Now I created another array in VC++ (0 to 3 and 0 to 2) ( same as
> > previous
> > > transposed array) and return to VB and I expected that (0 to 2,
0to3)
> > > should return in VB side.
> > > But I am getting (0 to 3 and 0 to 4) in VB instead of (0 to2 , 0
to
> > 3) -
> > > adding extra row and column
> > > I don't know Why
> > > Sample code.
> > > SAFEARRAYBOUND aDim[2]
> > > aDim[0].lLbound = 0;
> > > aDim[0].cElements = 4 ;
> > > aDim[1].lLbound = 0;
> > > aDim[1].cElements =3;
> > > BSTR HUGEP *pbstr;
> > > *ppOutputArray=SafeArrayCreate(VT_BSTR , 2, aDim);
> > > But If change to order its works I get (0 to 2 and 0 to 3 ) in VB
> > side.
> > > Please explain
> > > SAFEARRAYBOUND aDim[2]
> > > aDim[0].lLbound = 0;
> > > aDim[0].cElements = 3 ;
> > > aDim[1].lLbound = 0;
> > > aDim[1].cElements =4;
> > > BSTR HUGEP *pbstr;
> > > *ppOutputArray=SafeArrayCreate(VT_BSTR , 2, aDim);
> > > --
> > > Ravi .T. Ravigulan
> > > R&D Software Developer
> > > Manta Test Systems
> > > 4060B Sladeview Crescent, Unit#1
> > > Mississauga, ON L5L 5Y5
> > > Tel: 905-828-6469 x260
> > > Fax: 905-828-6850
> > > www.mantatest.com