Handling Windows API String Parameters
Category:Forms and Controls
Version Compatibility: Visual Basic 6
If you've ever had trouble sending parameters to the Windows API libraries, or getting returns, it's because the Windows API libraries are written in C. C has a different calling convention for parameters than VB. In the case of ByVal and ByRef, you are actually only passing a reference to the first character and passing a reference that contains a reference to the first character respectively. You also must make sure the string is large enough to hold the return value. The included snippet of code shows how to use the String method when calling DLLs.
Instructions: Copy the declarations and code below and paste directly into your VB project.