I have a query regarding the passing and returning of string parameters from VB to exposed function in dll written on VC.

Say in the given scenario below,
In VB bas module:
Declare function encode_str lib "encoder.dll" (ByVal strInput As String,
ByRef strOutput As String,ByRef strOuputLen As Long) As Long

In VC:
long encode_str(LPSTR strInput,LPSTR *strOutput,long *strOutputLen)

In VB form:
Dim strInput,strOutput As String
Dim strOutputLen As Long
Dim retval As Long

strOutput = String(256,vbNullChar)

retval = encode_str(strInput,strOutput,strOutputLen)
MsgBox strOutput



The above code seems to work once, but on further calls to "encode_str", the call fails to generate any strOutput result to be passed back to the VB form.

Anyone has any idea or suggestions? Thanks.