Hello,
VS 2008 3.5.Net
I am getting a string from a call back in a C++ native DLL which I have written. And for some reason it displays wrong something like this. i.e. [][[[[[[[[[[[[[ or ????????????????? with ASCII encoding.
My code is below. I think the DLL is using unicode, and I am trying to encode it in ASCII. The parameter in call back definition is char*. And in my C# I am using a string.
I have also tried Unicode, UTF-8, and ASCII. All of them display incorrectly.
Am I doing something wrong with my code?
Many thanks for any suggestions,
VS 2008 3.5.Net
I am getting a string from a call back in a C++ native DLL which I have written. And for some reason it displays wrong something like this. i.e. [][[[[[[[[[[[[[ or ????????????????? with ASCII encoding.
My code is below. I think the DLL is using unicode, and I am trying to encode it in ASCII. The parameter in call back definition is char*. And in my C# I am using a string.
I have also tried Unicode, UTF-8, and ASCII. All of them display incorrectly.
Am I doing something wrong with my code?
Many thanks for any suggestions,
Code:
*.hpp file ==============
typedef int (__stdcall *ptrIncomingCall)(int callID, char *caller);
MOBILEDLL_API int drvIncomingCall(ptrIncomingCall cb);
*.cpp file ==============
int drvIncomingCall(ptrIncomingCall cb)
{
int callerID = cb(20, "Joe bloggs");
return callerID;
}
C# code ===============
private delegate int incomingCallDelegate(int callerID, string caller);
[DllImport("MobileDLL.dll")]
static extern int drvIncomingCall(incomingCallDelegate cb);
int OnIncomingCall(int callerID, string caller)
{
this.label1.Text = callerID.ToString();
this.label2.Text = caller;
return 1;
}
private void button4_Click(object sender, EventArgs e)
{
drvIncomingCall((incomingCallDelegate)OnIncomingCall);
}