# WIN-32 C++ DLL in VC++ 6.0:: How to return a string from a function.



## nsevalia (Aug 28, 2003)

Hi all,

I have a problem of returing string from C++ DLL function. I am calling the DLL function from VBA program.

The function simply returns the value stored as a string variable in the DLL. I traced the DLL function by putting MessageBox in the DLL function, which shows the function is returning the correct value but when my VBA program receives the value it has more characters then it should have.

For eg. the DLL function returns "Naishadh"
the VBA program gets "Naishadh|||'3". [after Naishadh some garbage values]

Can anyone help me by showing a very simple example of returning strings from DLL successfully to the VBA program.

It will be very much helpful to me.


----------



## bigdrjake (Aug 27, 2003)

It sounds as if the string is destroyed before the call returns.

There are a lot of permutations on how your code might look, in terms of function declaration by value or reference. Don't know about the DLL issue, but I have seen this plenty of times in straight C++ code. Why don't you post more details of your routine.


----------

