Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning char* from C++ dll

Status
Not open for further replies.

howardnl

Programmer
Apr 12, 2001
18
0
0
US
Hello,

I've got a C++ dll that I need to call that returns a char* value. I've tried using this in C#, but I can't seem to get it to work. This is the way I'd like to do it, but my string is always blank.

[DllImport("stringReturn.dll")]
public static extern string GiveMeMyString();

Here is the call in my C# code (I always get an error):

MessageBox.Show(GiveMeMyString());

In my C++ dll I have a CString that I convert and return. If I set myString equal to a constant then it works.

myString = myCString.GetBuffer(myCString.GetLength());
return myString;


Any thoughts? Thanks for any help, I really appreciate it.

Thanks,
Nick
 
have you tried turning on "unsafe mode" so you can compile things with pointers? Thinking maybe you can return a char * just fine with that? The weevil of doooooooooom
-The eagle may soar, but the weasel never gets sucked up by a jet engine (Anonymous)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top