I'm writing a program that passes a const char*
from my C++
dll into my C#
code as a string. Certain characters don't pass the way I intend, which interferes with processing the string afterward.
For example, "ß.\x3"
in C++
becomes "ß®\x3"
when it reaches my C#
program. In another case, "(\x2\x2"
becomes "Ȩ\x2"
. I believe this may be a marshaling issue, but am not entirely sure.
Below is some relevant code:
C++
code:
typedef void (__stdcall * OnPlayerTextMessageReceivedCallback)(const char* entityId, const char* textMessage);
void
ProcessTextMessage(
const std::string& sender,
const std::string& message
)
{
m_onPlayerTextMessageReceivedCallback(sender.c_str(), message.c_str());
}
C#
code:
private delegate void OnPlayerTextMessageReceivedCallback(
[MarshalAs(UnmanagedType.LPStr)] string senderEntityId,
[MarshalAs(UnmanagedType.LPStr)] string message
);
I tried using marshaling the values with LPStr and LPWStr, but am still running into the same issues.
I appreciate any insight on what's happening here.