strDirectory = Left(strBuffer, intLength)
I use this function I got from a book to get the windows directory. What I am confused is strDirectory has the value of "C:\WINNT\System32" and its value comes from strBuffer while strBuffer is only passed to abGetSystemDirectory ByValue, so its value should not change. Did I miss some thing ? Thanks.
I'm not really sure about that but it's that way with a lot of api calls. This is what I thought of (feel free to correct it):
You gotta consider you are actually calling a C function. In C there is no seperate string data type. A string in C is a char (i.e. byte) array terminated with binary 0 (\0 escape sequence in C). So even if you wanted to pass a string ByVal you can't as nearly all C functions expect a pointer to the first element of a char array as parameter for a string. I don't know how the stuff is working with ASCII -> Unicode translation and stuff then but that's what I see from being a C/C++ programmer.
I'd be interested in a bit more insight on how VBA calls C functions as well.
Strings in VB are BSTR data types - which is just a pointer to a memory location with some header information and the actual string. So strings are not character arrays but pointers to character arrays. So byVal xxxx as string is actually functioning correctly - passing the guts of the BSTR which is a pointer.
See the following article in MSDN - "Passing Strings to a DLL Procedure"
I read a book about calling DLL procedure. I just found out, that ByVal in its parameter actually takes the address, not just the value. The keyword ByVal only means that the string is null-terminated because C language is used. Unlike when we create our own function using ByVal where it only passes the value.