Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

I am in front of a subtleties related to transfer an integers array from a c++ com automation assembly to a vb.net winform application.

the array is defined in vb.net winform and the values are intialized inside the ole automation method. When the method returns to the main application to display the contents of the array, the defined values are lost. Something goes wrong in the heap it seems.


The complete sample application is available from the following link: arraybounding

What could be the reason of my issue.
Thank you very much in advance.
Best regards.
MiQi

What I have tried:

have tried via a reference of the type library or late binding the effect is the same.

Here is the segmIent of the code I am trying to cover:
VB
Private _Layer As Object = Nothing
 Dim ArrValues(10) As Integer
 _Layer.Generate(ArrValues(LBound(ArrValues)), UBound(ArrValues

C++
BOOL CLayer::Generate(long FAR* IntegersArray, long Items)
{
      for (long Index = 0; Index < Items; Index++)
      {
            IntegersArray[Index] = Index + 1;
      }
      return TRUE;
}
Posted
Updated 18-Oct-16 4:31am
v2

1 solution

Your main issue is, that Integers in VB are short in VC. So you better use long as data type how it was discussed in this antique codeguru forum with some links.

Microsoft has done a great tutorial for that stuff.
 
Share this answer
 
Comments
Richard Deeming 18-Oct-16 14:01pm    
Integers in VB are short in VC

Are you sure? That was the case with VB6, but when VB.NET came out, the Integer type was redefined to be a 32-bit integer.
SuperMiQi 19-Oct-16 3:15am    
Hello,
I agreed with Richard, in VB.NET or C#,.., type of integer is a system.int32 (so 32 bits) which will match with a long c++ type. I have fixed the issue by using VARIANT to pass my array of integer and that works well.
Thank you.
Best regards.
MiQi.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900