|
-
March 12th, 2009, 06:22 AM
#1
[RESOLVED] Pass Integer Array to C++ Active Control
Hi,
I'm using VB.NET within Visual Studio 2008.
I have a ActiveX control on my form that contains a method that takes an Array. In VB6 I just passed in the array and it was populated OK. When I do the same in VB.NET, I get a result but the value of each index appears to be a pointer.
Here is the C++ method code...
void CMyCtrl::GetRowInfo(const VARIANT FAR& vArray, short sNumRows)
{
// Declaretemp array to put the row list into
short asRowList[24];
// populate temp array here
// Declare a SAFEARRAY to manipulate the VARIANT
SAFEARRAY FAR* FAR* ppsa = NULL;
short sCounter, sVal;
long ai[1]; // 1-D array index
// Variant access macro V_ARRAYREF(X) = V_UNION(X, pparray) = ((X)->pparray)
ppsa = V_ARRAYREF(&vArray);
// Check that we're only passing back a max of 24 row heights
sNumRows = sNumRows > LueScreenHigh ? LueScreenHigh : sNumRows;
// Copy the correct number of rows from psnRowList into a SAFEARRAY
for (sCounter = 0; sCounter < sNumRows; sCounter++)
{
ai[0] = sCounter;
sVal = asRowList[sCounter];
SafeArrayPutElement(*ppsa, ai, &sVal);
}
return;
}
Here is the VB code (same VB6 and VB.NET...
Dim maintRowList(0 To 23) As Integer
AxMyCtrl.GetRowInfo(maintRowList, 24)
In VB6, the value of maintRowList(0) is in the range 0 to Windows screen height (its a pixel value)
In VB.NET the value of maintRowList(0) is a value that looks like a pointer to me (e.g 285671429).
In VB.NET, the type of the 1st parameter is Object. In VB6 it is a Variant.
I've tried AxMyCtrl.GetRowInfo(maintRowList(0), 24) and got the same result.
I think I need to get a pointer to either the array or the first element of the array but I can't see a way to do that.
Can anyone suggest how I can pass an array to this type of C++ ActiveX method?
BTW - I cannot change the ActiveX code so the solution must be within VB.NET.
Thanks
Sanx
-
March 12th, 2009, 07:12 AM
#2
Re: Pass Integer Array to C++ Active Control
The solution is that in VB6 the Integers are 16-bit so I changed the definition of the array in VB.NET to...
Dim maintRowList(0 To 23) As Int16
...and all is well.
Sorry if I wasted anyone's time!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|