I am using C# code and need to call this method inside a C++ dll.
static std::wstring DecryptData(const std::wstring& strKey);
I've read many things and my best guess would be to pass something that is easier to read for both languages, like char-array or even byte-array and build the wstring in C++ and the string in C# afterwards.
Did anyone do that already?
Edit:
I read the linkes Topic but none of the answers helps me:
Using const
didn't help.
This is what I have now: C#
[DllImport(DLL_PATH, CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern string DecryptData([MarshalAs(UnmanagedType.LPWStr)]string strKey);
C++
extern "C" __declspec(dllexport) const std::wstring DecryptData(const std::wstring& strKey) {
return WlanHelper::CWirelessHelper::DecryptData(strKey);
}
This gives me a PInvokeStackImbalance =/