4
votes

I have a DLL programmed in C# which I am converting into a COM object for use in a VB6 application. Have have several methods and properties defined as long type which, when accessed in VB6, end up showing as "Unsupported variant type." Then I noticed that a function which is defined in C# as:

void Load(long firstNumber, int firstCheckDigit, long lastNumber , int lastCheckDigit)

Shows in my VB6 Object Browser as:

Sub Load(firstNumber As <Unsupported variant type>, firstCheckDigit As Long, lastNumber As <Unsupported variant type>, lastCheckDigit As Long)

Obviously, something about this conversion is turning the C# int type into a VB6 Long type which isn't a problem for me. However, I do need the firstNumber and lastNumber variables to be long both in C# and VB6. The variables on the backend cannot be int because of the size of some values being entered. Is there any way to do this? Or is a long type from the DLL side incompatible with COM objects?

2
Int means different things in .NET (32bit) and VB6 (16bit). So C#'s Int becomes VB6 Long (which is 32bit). There's no analogue for .NET Long (64bit) in VB6 - do you really need this precision?Yuriy Galanter
@YuriyGalanter You should provide some backing documentation in an answer :). You'd have my upvote.David L
@DavidL It's out there :) E.g. msdn.microsoft.com/en-us/library/vstudio/06bkb8w2.aspx Interop Considerations. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, remember that Integer has a different data width (16 bits) in other environments. If you are passing a 16-bit argument to such a component, declare it as Short instead of Integer in your new Visual Basic code. That's VB.NET, but it's the same. If OP'd like I will post this as an answerYuriy Galanter
@YuriyGalanter I actually do. These numbers are (potentially) 10-digit numbers so I've had overflows before where I'm using too large of a 10 digit number (north of the approx. 2 billion limit)redgrey85
Can you pass those as strings?Yuriy Galanter

2 Answers

6
votes

That's accurate, VB6 doesn't have a 64-bit integer type.

You'll need to accommodate it with int or double. The latter is unpleasant of course but you do get 15 digits out of it.