473,326 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Returning string from dll - memory leak?

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
Jul 22 '05 #1
1 2579
Anders Thomsen wrote:
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.
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sergey Tursanov | last post by:
Hello all ! When I use code below and check my program with various memory leak detection tools I get message about memory leaks in stl_alloc.h. #include <string> int main() { std::string s...
1
by: Guha | last post by:
I have a problem with returning a 2D array using a function which is called in main(). The piece of the code is given below. This is a test code only. #include"stdio.h" #include"alloc.h" ...
17
by: Chad Myers | last post by:
I've been perf testing an application of mine and I've noticed that there are a lot (and I mean A LOT -- megabytes and megabytes of 'em) System.String instances being created. I've done some...
11
by: Fred | last post by:
Hi I'm new to the std library. I have a function which reads data and creates a std string from it. I want to pass that back to the calling function as a parameter, not as the function return. ...
8
by: vidya.bhagwath | last post by:
Hello Experts, I am using std::string object as a member variable in one of the my class. The same class member function operates on the std::string object and it appends some string to that...
0
by: aton1 | last post by:
Hi, i have some questions regarding the use of datatype string in C++. I use g++ compiler and also use .ccmalloc to test for the memory leak. Here is a simple program that i have wrote which...
18
by: svata | last post by:
Hello to all, as a result from my previous post I'm busy with splitting code into functions. The one problem ( out of many ) I encounter is how to properly use/code a function which returns...
6
by: student1976 | last post by:
All Beginner/Intermediate level question. I understand that returning ptr to local stack vars is bad. Is returning foo_p_B from fnB() reliable all the time, so that using foo_p_A does not...
14
by: wahaha | last post by:
Hi, In a small code to implement string copy: while(*a++ = *b++) ; both a and b are char pointers. This code works but at the end, when *a = *b = '\0' finishes, both a and b step one block...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.