LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to pass a reference of a string into a VB .NET function

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?

 

 

0 Kudos
Message 11 of 12
(1,129 Views)

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.

Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
0 Kudos
Message 12 of 12
(1,114 Views)