What is ByVal 0&

I have seen the code below, but what is the meaning of "ByVal 0&"?

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long

Function InstanceToWnd(ByVal target_pid As Long) As Long
    Dim test_hwnd As Long, test_pid As Long, test_thread_id As Long
    test_hwnd = FindWindow(ByVal 0&, ByVal 0&)
End Function
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
byval 0& corresponds to the NULL (vbNull) value as parameter)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
william007Author Commented:
1. Will it be correct if I just put "0&" instead of "byval 0&"? What is that byval for?
2. What is the meaning of the symbol "&"?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
1) no. this is a "special" convention by vb for DLL function calls to pass a empty value for "pointer" values.
2) the & is also needed, it indicates that the data type of the 0 should be "long" and not integer or byte.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

william007Author Commented:
My last question,
1)Will it be correct if we put "byval &0" since sometimes we specify hexadecimal as &H15 etc..
Guy Hengel [angelIII / a3]Billing EngineerCommented:
the prefix & is another meaning the the postfix &, the postfix indicates the data type, while the & indicates that it is a hex value
william007Author Commented:
angelIII is correct (except for one portion I'll mention at the end) but as for more specifically why it's used in API functions..

Take this function for example:
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

The last parameter is declared ByRef (default when ByVal isn't mentioned) and as Any. Normally, it's used to pass certain structures (UDTs) ByRef but it's also meant to pass values ByVal. If you try to pass a Long value to that function, the DLL will attempt to write to protected memory (because it's ByRef) and cause your application to crash, most-likely. To overcome this, you'd have to pass it ByVal and type-cast it, such as..

    Call SendMessage(hWnd, WM_TEST, 0, ByVal 6&)
    Call SendMessage(hWnd, WM_TEST, 0, ByVal CLng(6))
    Dim val As Long
    val = 6
    Call SendMessage(hWnd, WM_TEST, 0, ByVal val)

This is also why you'll see the same functions, but named different with different declarations such as:

Private Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long

Oops forgot that last comment.

vbNull is a value in the Enum VbVarType equalling 1. I screwed up on that before as well. :-(
william007Author Commented:
Thansk for your additional comment, zzzzzooc:)
But where does Enum VbVarType declare?
william007Author Commented:
Thanks, I knew what you mean,
VbNull is vb internal Enum value, has a constant value 1 and we should compare it using
Thanks again for this precious info:)
It's not very relevant to this question but it's already declared within VB and it used by the VarType() function.

    Dim s As String
    Select Case VarType(s)
        Case VbVarType.vbString
            MsgBox "this is a string!"
    End Select

As for Null (VB keyword), I'm not sure of any specific use for it except for Variants to signify it contains nothing. angelIII was correct in saying 0& corresponds to a "null" value as 0 usually represents that in C/C++ but don't confuse that with the Null keyword. There's also vbNullChar (Chr(0)) (and vbNullString = "") and null-characters are generally used by other programming languages to terminate strings because they don't store their lengths (c/c++ for example actually have to loop through the entire string and find a null-char to know when the string ends!). VB uses BSTRs though, which store the strings' lengths, but that's a different topic.

    Dim v As Variant
    v = Null
    Select Case VarType(v)
        Case VbVarType.vbNull
            MsgBox "this is null!"
    End Select
william007Author Commented:
Thanks, this is very helpful!
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I see if posted vbNull (as reveiled by zzzzzzoc), let me correct to:
william007Author Commented:
Hi, angellll,
seems like it is more appropriate to be
"Null" :)
william007Author Commented:
as vartype(vbnullchar) = vbstring
but vartype(null) = vbnull
Too many things called null!

william is correct that vbNullChar is a string (Chr(0)) and wouldn't correspond with 0& but neither will Null, I don't think. 0& (or 0) still represents a "null", but not the Null keyword, a null-character or vbNull. It's just 0... which is probably just referred to as "null".

So.. There's a null term, a Null keyword, a Null character and a Null string. Let's not forget Empty. :)~ All have their proper uses and I'm not sure of every one of them.
william007Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.