Hi all,
I am learning to use API's but feel a bit confused with the way "ByVal" is used in the function Declare statement.By definition of a function if "ByVal" is used then the original argument is not affected.Here's my examle:
This obviously generates the output "C"\WINDOWS" as expected.Code:Option Explicit Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long Private Sub Command1_Click() Dim retstr As String * 255 Dim retval As Long retstr = "hello world" retval = GetWindowsDirectory(retstr, 255) Label1.Caption = retstr End Sub
My question is why should the string variable 'retstr' contain anything other than "hello world" since the argument is being passed as "ByVal"?


Reply With Quote
