Returning string from dll - memory leak?

A

Anders Thomsen

Hi,

I'm trying to return a string from a c++ dll in a method I load from VB.NET.
This is the method is defined like this:
extern "C" __declspec(dllexport) LPSTR GetData(BSTR hostExport, int
portExport)

The code I use for returning the string is this:
....
LPSTR lpReturnStr;
lpReturnStr = (LPSTR)malloc(strlen(csRef) + 1); //csRef is a CString
strcpy(lpReturnStr, csRef);
return lpReturnStr;

My question is, if the second line will cause a memory leak, as I do not
manually release the memory created by malloc.
Does the caller (in this case, the VB.NET application) free the string, or
should I do this in an other way?

Thanks
 
J

Jeff Schwab

Anders said:
I'm trying to return a string from a c++ dll in a method I load from VB.NET.
This is the method is defined like this:
extern "C" __declspec(dllexport) LPSTR GetData(BSTR hostExport, int
portExport)

The code I use for returning the string is this:
...
LPSTR lpReturnStr;
lpReturnStr = (LPSTR)malloc(strlen(csRef) + 1); //csRef is a CString
strcpy(lpReturnStr, csRef);
return lpReturnStr;

My question is, if the second line will cause a memory leak, as I do not
manually release the memory created by malloc.
Does the caller (in this case, the VB.NET application) free the string, or
should I do this in an other way?

Sorry, this isn't a question about C++, but about VB.NET. There's
really nothing in th C++ programming language to tell whether some
calling function will free the memory you have allocated. Please try a
news group dedicated to Windows programming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top