Heap corruption probelm when i try to return std::string from function in dll

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2009
Posts: 16
Reputation: dhpatil1 is an unknown quantity at this point 
Solved Threads: 0
dhpatil1 dhpatil1 is offline Offline
Newbie Poster

Heap corruption probelm when i try to return std::string from function in dll

 
0
  #1
Feb 5th, 2009
Hi all,
I am working on vs2005 (vc++8).
I have created one dll in vs2005(vc++8), in that we have one function which returns "std::string" .

when i load this dll in another vs2005(vc++8) application and call the function which returns "std::string",
we get following error:

Windows has triggered a breakpoint in vstestdll.exe.

This may be due to a corruption of the heap, and indicates a bug in vstestdll.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information


For more detail code is as follows:
  1.  
  2. dll function :
  3.  
  4.  
  5.  
  6. std::string getDH1(int clo)
  7.  
  8. {
  9.  
  10.  
  11.  
  12. return std::string("abcdefghijklmnopqr");
  13.  
  14. }
  15.  
  16.  
  17.  
  18.  
  19.  
  20. .exe code:
  21.  
  22.  
  23.  
  24. #define TEST2_API __declspec(dllimport);
  25.  
  26. TEST2_API std::string getDH1(int clo);
  27.  
  28.  
  29.  
  30.  
  31.  
  32. int _tmain(int argc, _TCHAR* argv[])
  33.  
  34. {
  35.  
  36.  
  37.  
  38. string sam =getDH1(1);
  39.  
  40.  
  41.  
  42. return 0;
  43.  
  44. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 360
Reputation: jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice jencas is just really nice 
Solved Threads: 69
jencas jencas is offline Offline
Posting Whiz

Re: Heap corruption probelm when i try to return std::string from function in dll

 
0
  #2
Feb 6th, 2009
What happens if you rewrite your dll function:

  1. void getDH1(int clo, std::string & str);
Last edited by jencas; Feb 6th, 2009 at 6:43 am.
If you are forced to reinvent the wheel at least try to invent a better one!

Please use code tags - Please mark solved threads as solved
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 625 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC