I am looking at migrating some legacy COM code written in VB6 to .NET, however, for this I need to generate a type library that is close enough to the original.
I ran into the problem of passing an array of parameters when binding early with other VB6 components. In the original VB6, the signature looked like this:
Public Function ExecSPReturnRS(ByVal strProcAs String, _
ParamArray varParams() As Variant) As Recordset
and generated a MIDL that looks like this:
[id(0x60030009), vararg]
HRESULT ExecSPReturnRS([in] BSTR strProc,
[in, out] SAFEARRAY(VARIANT)* varParams,
[out, retval] _Recordset** );
With C #, I cannot determine the correct declaration to generate the same MIDL. I either skip the declaration vararg, or the varParams parameter is declared as SAFEARRAY(VARIANT)and not SAFEARRAY(VARIANT)*.
So if in C # I declare how:
Recordset ExecSPReturnRS(string storedProc, ref object[] arguments);
... I get SAFEARRAY(VARIANT)*, but not vararg. However, if I declare how
Recordset ExecSPReturnRS(string storedProc, params object[] arguments);
... then I get varargbut SAFEARRAY is not declared as a link.
, MarshalAsAttribute MarshalAsAttribute , , , :
Recordset ExecSPReturnRS(string storedProc,
[MarshalAs(UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]
object[] arguments);
MIDL, params MarshalAs.
, , MIDL , ref params, #. ?
Edit: It seems that there is some confusion about what the ultimate goal is. Essentially, we have an application that consists of many legacy VB6 components. To remove legacy debt, we need to be able to move VB components gradually in .NET. If this component is dependent on other components, you must use .NET with existing VB6 and classic ASP, ideally without changing the code. Some legacy components will be completely reorganized and will not be dependent on COM. Many of the components of VB6 use early binding., param .NET ParamArray VB6, VB6 , , , , . Visual Basic VB. ref, : .
VB6 , , :
Set rs = dbconn.ExecSPReturnRS("dbo.StoredProc", _
Array("@param1", value), _
Array("@param2", value))
, , , VB . , , , VB , , , . , , VB6, , , . , .
: /PoC, , , . , . COM, - , . , COM- , , , .