Open NETSphereSoft opened 1 week ago
First, the GitHub repos focus on .NET Core. .NET Framework specific issues should go to VS Developer Community, but this is a feature change that won't be accepted at all.
The topic about COM interop belongs to https://github.com/dotnet/runtime . The COM interop story are considered legacy and will be maintained focus on compatibility. ParamsArray
is a .NET only concept and won't have any effect to COM. Changing the mapped COM type for params array is a breaking change and will definitely not happen. Using existing mechanisms with ref
, [In]
and [Out]
is the only and expected solution.
It's especially a non-goal to incorporate new idiomatic in .NET with COM, especially VB6 which is more legacy and won't receive and feature change.
Describe the bug
We want to provide a .NET Framework library for VB98/VB6 developers and take advantage of
ParamArray
usage.The standard translation from .NET
params
to IDL/TLB by TlbExp.exe is
Which is seen in VB98/VB6 object catalog as
But this COM/ActiveX method signature is accessible with
MSScriptControl.ScriptControl
only, not with VB98/VB6. The compiler notices an error of incompatibility:For VB98/VB6 the following IDL/TLB method signature is required (reference of
SAFEARRAY
):Our current workaround is to change the method signature in .NET:
which get generated in IDL/TLB with no
vararg
, butSAFEARRAY
reference:Then we need manually to do the following process:
vararg
You can see this in the sample project:
TypeLibParamArrayVB6.IDL
line 59 andTypeLibParamArrayVB6.VB98.IDL
line 59To Reproduce
Add
method ofClass1
in your projectTypeLibParamArrayVB6.VB98.IDL
(can be build withTypeLibParamArrayVB6.VB98.bat
)TypeLibParamArrayVB6.VB98.tlb
toTypeLibParamArrayVB6.tlb
and place it to yourTypeLibParamArrayVB6.dll
AddVB98
method ofClass1
in your project nowCall class1.AddVB98("Test 1")
Call class1.AddVB98("Test 1", "Test 2")
Call class1.AddVB98("Test 1", "Test 2", "Test 3")
Possible solution
Add a
ParamArrayRef
attribute for placing at the parameter or method additionally to the standardparams
usageor
And export then the IDL/TLB by
TlbExp.exe
with the requested method signature:Alternately a solution with existing
InAttribute
andOutAttribute
could be to get the same method signature like VB98/VB6 does:to lead into
And a much simplier could be (currently prevented from compiler):
to lead into
Further technical details
Microsoft Visual Studio Professional 2019 Version 16.11.37 VisualStudio.16.Release/16.11.37+34931.43 Microsoft .NET Framework Version 4.8.09037