To return a String from a dll to VB6.
Declare in VB6
Public Declare Function QueryString Lib "lihelper" Alias "_QueryString@4" (ByVal key As String) As String
Call in VB6
Dim s as String : s = QueryString("find me")
Define in C++ DLL
extern "C" __declspec(dllexport) BSTR __stdcall QueryString(LPCSTR key{
const std::string response(key? odbc::sql::query(key) : std::string(""));
return SysAllocStringByteLen(response.c_str(), response.size());
}
Vb6 will always convert a returning string from a DLL as if it's multibyte, that's why your Unicode-strings will only contain their first character (unless it's >0xFF of course).
Normally I allocates a buffer of reasonable predefined size and sees if the returning data fits. The function the returning the needed size. If the needs are greater, I'll give in and reallocates ...