C++ DLL Called From C# on Windows CE for ARM Always Returns 0
-
21-08-2019 - |
Question
I am currently developing an application for Windows CE on the TI OMAP processor, which is an ARM processor. I am trying to simply call a function in a C++ DLL file from C# and I always get a value of 0 back, no matter which data type I use. Is this most likely some kind of calling convention mismatch? I am compiling the DLL and the main EXE from the same Visual Studio solution.
C# Code Snippet:
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
byte test = LibWrap.test_return();
MessageBox.Show(test.ToString());
}
}
public class LibWrap
{
[DllImport("Test_CE.dll")]
public static extern byte test_return();
}
C++ DLL Code Snippet:
extern "C" __declspec (dllexport) unsigned char test_return() {
return 95;
}
Solution
It worked when I changed:
extern "C" __declspec (dllexport) unsigned char test_return() {
return 95;
}
to
extern "C" __declspec (dllexport) unsigned char __cdecl test_return() {
return 95;
}
In the DLL code. Why it doesn't assume this when compiled for WinCE is beyond me.
OTHER TIPS
Try exporting test_return() as follows:
unsigned char __declspec(dllexport) WINAPI test_return() {
return 95;
}
Somewhere WINAPI is being defined as __stdcall where it should have been __cdecl
No. WINAPI is defined as __stdcall.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow