07-12-2010 09:06 AM
So Ref does not equal to Pointer? I thought they both refer to the memory address of the variable. Can you tell a little the difference?
07-19-2010 01:29 AM
A string can never be referenced by value but must be a pointer. As such it is indeed always at least a reference. However I'm not sure if the Visual Basic byRef has that meaning for strings, at least it wouldn't make much sense.
But you can pass a string pointer by reference which will result in a pointer to a pointer being passed. This is the only way a function can change the pointer itself and return it back to the caller, but at the same time it is a memory management nighmare, since the caller and callee need to agree exactly what memory management routines to use. For instance on windows calling C runtime functions malloc(), free(), and realloc() in one and one of the Windows API memory managment functions by the other is going to create a big mess. Also you can't mix and match the various Windows memory APIs either since they have different strategies to how the memory is allocated and managed. Last but not least if you write a DLL you can't just assume that malloc() and co will work either since your DLL might link to a different C runtime version than the application that references your DLL.