Problem dereferencing a string from .NET

Hi,

I'm calling a c++ DLL via DLLImport and interop this way:

[DllImport("UtilsAK.dll")]
public static extern int ValueOK(ref string pwd, ref string generalResult);

private void button1_Click(object sender, EventArgs e)
{
string pwd = "e45shjwll3";
string generalResult = "";
int returnValue = ValueOK(ref pwd, ref generalResult);
}

However, in the c++ code I need to retrieve the string value and work with it so I can change it. The app crash when I dereference the string value. Here's the code:

int ValueOK(std::string *pwd, std::string generalResult)
{
std::string newValue;
std::string _pwd = *pwd; <---- crash here

for (int temp = 0; temp < _pwd.length(); temp++){
newValue += "e";
//stuff to do....
}

*pwd = newValue;

return 0;
}


Please, any solution or workaround about this?

Thanks in advance!


std::string _pwd = *pwd;

pointer string cannot be assigned to string .

std::string _pwd = pwd;
I'm not assigning a pointer, but dereferencing it
Last edited on
I think that the problem is that the internal representations of System.String in C# and std::string in C++ are different. Are you able to pass around basic types such as int like this? Try doing it with a char array instead of string.
But how can I change the value of a char array passed by reference? The point is that I need in c# the value changed by c++
Topic archived. No new replies allowed.