I have a c# program that checks data base strings from a c++ dll.
I already read this pages :
- How to pass strings from C# to C++ (and from C++ to C#) using DLLImport?
- Passing strings from C# to C++ DLL and back -- minimal example
My strings pass well with no error but my problem is they're not matching in C++ dll.
I tried to check them out with Messagebox , Console and Everything and they are same at characters , size , text ...
but If Else always returns false ...
My C++ code ( test_match.dll ) :
extern "C" __declspec(dllexport) int check_string(const char* string_from_csharp);
int check_string(const char* string_from_csharp)
{
if (string_from_csharp == "hello world!" ){
return 1;
}else{
return 0;
}
}
My C# code :
[DllImport("test_match.dll",
CallingConvention = CallingConvention.Cdecl ,
CharSet = CharSet.Unicode)]
private static extern int check_string(string string_from_csharp)
My C# code of usage ( WPF ) :
int get_match_state = check_string(inputtext.Text);
MessageBox in C++ , says ... input is "hello world!"
But it always returns 0
Also , I tried to convert them to wchar_t , std::string with find() but nothing changed.
Where do I make a mistake? Thanks