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

We are migrating a product from VB6 to VB.NET and facing an issue.
This product interacts with a function defined in VC++ component (.ocx).

1. VB6 & VB.NET function call:

VB
result = TestFunc(Param1, Param2, Param3)


2. VC++:
a) Function definition in .CPP file:
C++
long TestFunc(long FAR* Param1, const VARIANT FAR& Param2, long Param3)
       {
       ...
       }


DISP_FUNCTION(Ctrl, "TestFunc", TestFunc, VT_I4, VTS_PI4 VTS_VARIANT VTS_I4)

b) Function signature in .ODL file:
C++
long TestFunc(long* Param1, VARIANT Param2, long Param3);


c) Function signature in .h(header) file:
C++
afx_msg long TestFunc(long FAR* Param1,  const VARIANT FAR& Param2, long Param3);



"Param2" in above "TestFunc" is defined as byte array in VB6 & VB.NET.

In VC++, the corresponding type for "Param2" in "TestFunc" is - "const VARIANT FAR& Param2".

In VB6, the byte array values passed gets modified in VC++ "TestFunc" & the modified values are received in VB6 "Param2" variable.

Issue in VB.NET:

In VB.NET, the byte array values passed gets modified in VC++ "TestFunc".
However, the modified values are not transferred from VC++ to VB.NET. The "Param2" variable still has the original values & not the modified values.

Could you please provide us information on how to obtain the modified byte array values in VB.NET from the Variant variable in VC++ component?

Thanks in advance.
Posted
Updated 21-Jan-16 0:58am
v4
Comments
F. Xaver 21-Jan-16 3:16am    
what is your VB.Net definition of TestFunc call? maybee just need to set Param2 as ByRef
Revati513 21-Jan-16 4:38am    
Hello Xaver,

Thank you for the quick response.
The VB.NET definition for TestFunc call is as below:

Public Overridable Function TestFunc(ByRef Param1 As Integer, Param2 As Object, Param3 As Integer) As Integer

We changed the type of Param2 to VARIANT* in below function signature of .odl file.
This changed the VB.NET definition of Param2 to ByRef. However when TestFunc function was called in Vb.net, type mismatch error occurred.

Function signature in .ODL file:
long TestFunc(long* Param1, VARIANT Param2, long Param3)

Thanks.
F. Xaver 21-Jan-16 10:09am    
without ByRef for Param2 VB.Net won't copy the data back to Param2

Public Overridable Function TestFunc(ByRef Param1 As Integer, ByRef Param2 As Object, Param3 As Integer) As Integer

Revati513 25-Jan-16 4:08am    
Hello Xaver,

Thank you for the suggestion. We changed the .ODL, .CPP, .H files signature of TestFunc to accept the value of Param2 as reference.

C++:

.ODL:

long TestFunc(long* Param1, VARIANT* Param2, long Param3);

.CPP:

long TestFunc(long FAR* Param1, VARIANT* Param2, long Param3)
{
...
}

DISP_FUNCTION(Ctrl, "TestFunc", TestFunc, VT_I4, VTS_PI4 VTS_PVARIANT VTS_I4)

.H:

afx_msg long TestFunc(long FAR* Param1, VARIANT* Param2, long Param3);

#define VTS_PVARIANT "\x4C" // a 'VARIANT*'

VB.NET:

Function declaration:
Public Overridable Function TestFunc(ByRef Param1 As Integer, ByRef Param2 As Object, Param3 As Integer) As Integer

Param2 declaration inside a user defined structure in vb.net:
Dim Param2() As Byte

Function call:
result = TestFunc(Param1, Param2, Param3)

The function declaration in VB.NET now shows ByRef for Param2.

However, when TestFunc function is called in VB.NET following error occurs:

"Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))"

Thanks.

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