
VB calling C++ DLL returning an array??
Try this URL:
http://support.microsoft.com/support/kb/articles/Q
177/2/18.ASP
Quote:
> Matt,
> Try something like this:
> Private Sub MyArrExample lib "MyDLL.dll" (byval
NumItems as Integer, ByRef
Quote:
> RetArray As Integer)
> and use something like:
> Redim RetArr(14) as Integer
> MyArrExample 15, RetArr(0)
> The C++ end would be something like:
> extern "C" void WINAPI MyArrExample(short
iNumItems, short *lpsRetArray)
Quote:
> {
> short i;
> for (i = 0; i < iNumItems; i++)
> lpsRetArray[i] = i;
> }
> If it is really important for you to return an
array, you can do it. You
Quote:
> use a Variant in VB and a VARIANT in C. It is
fairly messy though and I
Quote:
> don't have an example immediately to hand.
Post back if you really want to
Quote:
> see this and I'll try and dig up an example.
> HTH
> Peter
> > Hello-
> > I am having problems returing an array in a
VB application when I a
Quote:
> function
> > in a c++ DLL. I get a referenced memory
error. I know the DLL is being
Quote:
> > called correctly, but an error occurs at the
point of returning the array.
Quote:
> > Here is a snipit of code from the VB and VC++
applications. Thanks in
Quote:
> > advance for any help!
> > '*********************VB6.0
Code**********************************************
*******************
Quote:
> > Dim RetArray() As Integer
> > ReDim RetArray
(intNumBytes) 'redim the array
that is
Quote:
> expected
> > RetArray = ReturnArray(intNumBytes) 'call
function in dll, return
Quote:
> > type=array of integers
> '***********************************************
****************************
Quote:
> > *************************
> > file://*********************VC++6.0
Code**********************************************
***************
Quote:
> > int * Add::ReturnArray(int numberbytes)
> > {
> > int Value[100];
> > for(short int i=0;i<numberbytes;i++)
> > {
> > Value[i] = i;
> > }
> > return(Value);
file://*******************************************
**************************
Quote:
> *****
> > **************************
> > Best Regards,
> > Matt Van Bergen
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.