Passing 2D array between VB And VC++ 
Author Message
 Passing 2D array between VB And VC++

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

I



Sun, 18 Jul 2004 03:46:03 GMT  
 Passing 2D array between VB And VC++
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


Quote:
> 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




Mon, 19 Jul 2004 03:51:40 GMT  
 Passing 2D array between VB And VC++
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;

Quote:
}

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


Quote:
> 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




Mon, 19 Jul 2004 05:27:38 GMT  
 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




Mon, 19 Jul 2004 05:33:42 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. How To pass 2D String array to VB from VC++ Using Safe array

2. Which 2D array of 2D array addressing method?

3. 2D array of pointers to 2D arrays

4. Passing string Arrays between VB and VC

5. Passing array from VB to VC

6. Passing an array VC++ COMM => VB

7. Passing array from VB to VC++

8. passing short array parameters to VC++ DLL in VB

9. HOWTO: Pass VB UDT that contains an array to VC dll

10. Pass array ByRef from VB to VC 6 DLL

11. Passing an VB array by reference to a VC Win32 DLL

12. Passing array of Strings between VB and VC

 

 
Powered by phpBB® Forum Software