Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ DLL Called From C# on Windows CE for ARM Always Returns 0

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;
}
like image 232
Ben McIntosh Avatar asked Nov 23 '25 22:11

Ben McIntosh


1 Answers

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.

like image 75
Ben McIntosh Avatar answered Nov 26 '25 13:11

Ben McIntosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!