I have a C# application that reference a VB6 dll. When I pass null from C# into VB6 dll function, the null is translated as value Empty (value) in VB6, instead of Nothing (object). For example:
// function in vb6 dll that referenced by c# app
Public Sub TestFunc(ByVal oValue As Variant)
{
...
if oValue is Nothing then
set oValue = someObject
end if
...
}
// main c# code
private void Form1_Load(object sender, EventArgs e)
{
object testObject = new object();
testObject = null;
TestFunc(testObject);
}
When I pass an object (not null) then it will be passed into the VB6 as object. But when null passed into vb6, it becomes value type Empty, instead of object type Nothing. Any one knows why? and is there anyway I can force null as Nothing in VB6 when passed from c# app?
Thanks a lot.
Because C comes after B The reason why the language was named “C” by its creator was that it came after B language. Back then, Bell Labs already had a programming language called “B” at their disposal.
C is an imperative, procedural language in the ALGOL tradition. It has a static type system. In C, all executable code is contained within subroutines (also called "functions", though not in the sense of functional programming).
C, computer programming language developed in the early 1970s by American computer scientist Dennis M. Ritchie at Bell Laboratories (formerly AT&T Bell Laboratories).
C is a procedural language that supports structured programming; it has a static system and a compiler written in C itself. Since its release, C became a milestone of computing history and has become the most critical component throughout the computer industry.
Some more information, rather than an answer. I just ran this VB6 scratch program to confirm whether Nothing
can be passed ByVal
. It can be.
Private Sub Form_Load()
Call TestSub(Nothing)
End Sub
Private Sub TestSub(ByVal vnt As Variant)
Debug.Print VarType(Nothing)
Debug.Print VarType(vnt)
If vnt Is Nothing Then Debug.Print "vnt Is Nothing"
If IsEmpty(vnt) Then Debug.Print "vnt Is Empty"
End Sub
I got the following output. Note that 9 is vbObject and indicates a Variant holding an Object reference.
9
9
vnt Is Nothing
I haven't tested moving TestStub into another component but I think that'd still work. So I think the .NET marshalling to COM could do better.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With