Question about ByVal keyword? 
Author Message
 Question about ByVal keyword?

Hi,
What is the difference between declaring a function with
a ByVal keyword and calling a function with a ByVal keyword?
For example:

Private Declare Function LookupAccountSid Lib "advapi32.dll" _
Alias "LookupAccountSidA" ( _
    lpSystemName As Any, _
    Sid As Long, _
    name As Any, _
    cbName As Long, _
    ReferencedDomainName As Any, _
    cbReferencedDomainName As Long, _
    peUse As Integer _
) As Long

error3 = LookupAccountSid(ByVal 0&, _
                          ByVal pOwner_SID, _
                          ByVal name, _
                          Nameleng, _
                          ByVal ReferencedDomainName, _
                          cbReferencedDomainName, _
                          peUse)

David



Fri, 16 Nov 2001 03:00:00 GMT  
 Question about ByVal keyword?
No difference.  Several API functions, especially those which have a parameter
which is declared "As Any", sometimes need that parameter sent ByVal and
sometimes ByRef (most notably the SendMessage function).  The ByVal is left
out of the declaration so that in the calling statement you can use whichever
keyword is appropriate for that call.

Lee Weiner
weiner AT fuse DOT net
http://home.fuse.net/lweiner


Quote:

>Hi,
>What is the difference between declaring a function with
>a ByVal keyword and calling a function with a ByVal keyword?
>For example:

>Private Declare Function LookupAccountSid Lib "advapi32.dll" _
>Alias "LookupAccountSidA" ( _
>    lpSystemName As Any, _
>    Sid As Long, _
>    name As Any, _
>    cbName As Long, _
>    ReferencedDomainName As Any, _
>    cbReferencedDomainName As Long, _
>    peUse As Integer _
>) As Long

>error3 = LookupAccountSid(ByVal 0&, _
>                          ByVal pOwner_SID, _
>                          ByVal name, _
>                          Nameleng, _
>                          ByVal ReferencedDomainName, _
>                          cbReferencedDomainName, _
>                          peUse)

>David



Fri, 16 Nov 2001 03:00:00 GMT  
 Question about ByVal keyword?
I would say none....

However, you must be sure that you are calling the function in the
expected way.  I would strongly recommend, especially with an API call,
that both ByVal, and ByRef keywords be specified in the Declare.

VB defaults to ByRef, so if nothing is specified then the parameter is
being passed ByRef (as a pointer), and changes made to it in the
function change the value back in the VB program.

I do not see any point in adding the ByVal or ByRef keywords when you
call the function, as this would add confusion and possible problems if
they are not the same as in the Declare.

Quote:

> Hi,
> What is the difference between declaring a function with
> a ByVal keyword and calling a function with a ByVal keyword?
> For example:

> Private Declare Function LookupAccountSid Lib "advapi32.dll" _
> Alias "LookupAccountSidA" ( _
>     lpSystemName As Any, _
>     Sid As Long, _
>     name As Any, _
>     cbName As Long, _
>     ReferencedDomainName As Any, _
>     cbReferencedDomainName As Long, _
>     peUse As Integer _
> ) As Long

> error3 = LookupAccountSid(ByVal 0&, _
>                           ByVal pOwner_SID, _
>                           ByVal name, _
>                           Nameleng, _
>                           ByVal ReferencedDomainName, _
>                           cbReferencedDomainName, _
>                           peUse)

> David



Fri, 16 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. What's the difference between ByVal and not ByVal

2. Questions regarding objects, assignments, byval, byref, etc...

3. Question on ByVal

4. Passing Parameters - A ByRef vs ByVal Question

5. Question: Verify my hypothesis about ByVal args to DLL functions

6. Passing ADO objects byval question?

7. ByVal or Byref : performance question ?

8. ByVal or Byref : performance question ?

9. A question about ByVal

10. Return Keyword question

11. "NEW" keyword - question

12. NewB question "Like" keyword

 

 
Powered by phpBB® Forum Software