Ben McIntosh
Ben McIntosh

Reputation: 1552

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;
}

Upvotes: 3

Views: 2062

Answers (3)

Jeffrey Walton
Jeffrey Walton

Reputation: 255

Somewhere WINAPI is being defined as __stdcall where it should have been __cdecl

No. WINAPI is defined as __stdcall.

Upvotes: 0

Alan
Alan

Reputation: 13721

Try exporting test_return() as follows:

unsigned char __declspec(dllexport) WINAPI test_return() {
   return 95;
}

Upvotes: 0

Ben McIntosh
Ben McIntosh

Reputation: 1552

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.

Upvotes: 2

Related Questions