Originally Posted by MSDN
... Functions should return types that VBA can recognize ByVal. This means that some types are more easily returned by modifying arguments in place: strings, arrays, user-defined types, and objects.
...
To return a byte string to VBA from a DLL, you should modify a byte-string BSTR argument in place. For this to work, you must declare the DLL function as taking a pointer to a pointer to the BSTR and in your C/C++ code, and declare the argument in the VBA code as ‘ByRef varg As String’.
You should only handle strings that are passed in these ways from VBA using the OLE BSTR string functions to avoid memory-related problems.