I'm using VS2012 and trying to call a function in a C# project from a C DLL I've written. The C DLL is called by an external app (Thunderbird).
I've found the Unmanaged Exports page and followed the instructions. In the process, my C# project had to be set to .net4 and x86 to get everything to compile and link as far as it does. But I have a linker error I can't resolve, and since this is uncharted territory for me it may be I'm just doing something stupid.
In my C# I have;
using RGiesecke.DllExport;
namespace StreamAttacher
{
class Test
{
[DllExport("add", CallingConvention = CallingConvention.Cdecl)]
public static int TestExport(int left, int right)
{
return left + right;
}
}
}
And in my C I have
#include<stdio.h>
int add(int left, int right); //in c#
__declspec(dllexport)char* strTest2()
{
int i = add(2,3);
char *p = "C:\\Work\\Mozilla\\Test dir\\testfile.zip";
return p;
}
The C project references the C# project in its external dependencies.
On building, I get the linker error "error LNK2019: unresolved external symbol _add referenced in function _strTest2"
If I look at the C# DLL using DllExp then I see nothing exported. Should I? I was expecting to see the "add" function but it's not there, and nor are any errors generated when I build the C# DLL on its own.
Also, is that proto for 'add' in the C code all I need if things are working right further back along the chain?