I have a VB6 app and a C# Wrapper for a C object.
It works fine as built, however now I am trying to Return two values from the C# wrapper back to the VB6 app instead of the original one value being returned, and now I am getting the message - Wrong number of arguments or invalid property assignment.
I am guessing I just don't know how to correctly return multiple values. I have googled of course and applied a few ideas but still no go.
The working code looks like this.
VB6 app
Dim Result_ As BioxScan_Status
Result_ = ObjWinBio.OpenDevice
C# DLL
public BioxScan_Status OpenDevice()
{
.........
return BioxScan_Status.Connected ;
}
public enum BioxScan_Status
{
Connected,
Disconnected,
Idle,
Busy,
Completed,
Error,
CaptureComplete
}
The above code works fine, the VB6 app calls the C# fucntion and gets the Return value of BioxScan_Status.Connected
However ...
What I am now trying to do is get Two values returned. One String value, One Int value, namely BioxScan_Status.Connected and also a UnitID
Here is what I have tried
C# DLL
public (string, string) OpenDevice()
{
.........
return (Convert.ToString(BioxScan_Status.Connected), Convert.ToString(_unitId));
}
public interface IWinbioWrap
{
[DispId(1)]
//BioxScan_Status OpenDevice(); // done
(string, string) OpenDevice();
..........
}
VB6 App
Dim Res()
Res = ObjWinBio.OpenDevice("", "")
On this line - Wrong number of arguments or invalid property assignment
Appreciate any thoughts.
Cheers
In VB6, you can't directly return a tuple. However, you can work by returning a custom class. Here's the modified C# code:
public class BioxScanResult
{
public string Status { get; set; }
public string UnitId { get; set; }
}
public BioxScanResult OpenDevice()
{
...
var result = new BioxScanResult
{
Status = BioxScan_Status.Connected.ToString(),
UnitId = _unitId.ToString()
};
return result;
}
Now, you can update your VB6 code to work with the BioxScanResult class:
Dim Res As Object
Set Res = ObjWinBio.OpenDevice()
Dim Status As String
Dim UnitId As String
Status = Res.Status
UnitId = Res.UnitId