Here are some important information.
- Strings are always passed to DLL functions by reference, the DLL function can modify the value of the string argument.
- DLL function returns a string into an argument of type String that was passed to the function
- Usually a DLL function returns long integer
- To call a DLL function that writes to a String variable, you need to take additional steps to format the string properly.
- String variable must be a null-terminated string. A null-terminated string ends in a special null character, which is specified by the VBA constant vbNullChar
- A good way to pass a string to a DLL function is to create a String variable and use the String$ function to fill it with null characters
Code: Select all
str = String(256, vbNullChar)
- After getting the return, you can call the following code to extract the string.
Code: Select all
str = Left(str, InStr(1, str, vbNullChar) - 1)
- A good way to pass a string to a DLL function is to create a String variable and use the String$ function to fill it with null characters
- DLL function can't change the size of a string once it has been created. Therefore, you need to make sure that the string that you pass to a function is large enough to hold the entire return value
- String variable must be a null-terminated string. A null-terminated string ends in a special null character, which is specified by the VBA constant vbNullChar