How to receive a large string back from a C++ DLL in VB6

Viewed 109

I need to be able to return a value > 65535 characters from a Unicode C++ DLL.

In order to call a C++ DLL, I have my VB6 declaration as:

Private Declare Function MyFunction Lib "mydll.dll" (ByVal uStringIncoming As String, ByVal uStringOut As String) As Long

And I call the function with this code snippet:

Private Function sFunc(sIncoming as String) As String
    Dim uReturnString As String
    Dim uIncoming_Local As String
    Dim rv as Long
    uIncoming_Local = StrConv(sIncoming, vbUnicode)
    ' A fixed length string in VB6 is limited to 64KB in length (65535)
    uReturnString = String$(65535, vbNullChar)
    rv = MyFunction(uIncoming_Local, uReturnString)
    If (rv == 0) Then
        sFunc = StrConv(uReturnString, vbFromUnicode)
    End If
End Function

MyFunction can handle any size incoming string, but iIf the return string is > 65535 characters, the function crashes because the uReturnString is only 65535 chars long.

How do I get around this limitation?

0 Answers
Related