By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,505 Members | 1,761 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,505 IT Pros & Developers. It's quick & easy.

Passing String from C++ DLL to C#

P: 1
Hi,

I've got a C++ DLL and a C# GUI. The DLL gets a value and then needs to pass it back to the C# program in the form of a string.

I know this is probably a glaringly simple thing to achieve but it's escaping me at the moment.

I want something simple like this, a function that I can call from the C# part of my program that returns a string that I can then print to file/messagebox or whatever:

extern "C" __declspec(dllexport)
string DataToReturn()
{
string test="TEST";
return test;
}

I've tried a few combinations of char/string etc but seem to always come accross access violation exceptions.

Anyone have any insight into this? :)
Nov 17 '08 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
Read up on C++ /C# interoperability. There are many topics on this in MSDN.

The extern "C" only applies to making a C++ function callable from a C program. It does nothing to help with C#.

A C++ string is not a C# String.
Nov 17 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.