SHARE
TWEET

Untitled

a guest Mar 13th, 2012 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. The Trace prints "????????" not "test"
  2.  
  3. C++
  4.  
  5. extern "C" char* CSharp_Test_ReturnString()
  6. {
  7.   string s = "test";
  8.   int len = s.length();
  9.   char* comem = (char*)CoTaskMemAlloc(len+1);
  10.   strcpy_s(comem, len+1, (const char*)ba);
  11.   return(comem);
  12. }
  13.  
  14. C#
  15. [DllImport("__Internal", EntryPoint = "CSharp_Test_ReturnString")]
  16. public extern static string CSharp_Test_ReturnString();
  17.  
  18.  
  19. void TestInterop()
  20. {
  21.   string tr = CSharp_Test_ReturnString();
  22.   Trace.WriteLine(string.Format("ReturnString: {0}", tr));
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top