I’m busy getting to know a tiny bit of C/C++, and interop with C#. I’ve checked several examples of creating a simple Win32 DLL and using this from C#, but when I try and call into my DLL, I get the runtime error: ‘Unable to find an entry point named TestFunc’. My DLL looks like this, and I created it from a Win32 DLL project, with the empty project option:
Header:
__declspec(dllexport) int TestFunc(char *, char *, char *);
Code file:
#include 'stdafx.h' #include 'TestLib.h' __declspec(dllexport) int TestFunc(char *arg1, char *arg2, char *arg3) { char str1[] = 'Brady Kelly'; char str2[] = 'Hello World'; char str3[] = '1234567890'; strcpy(arg1, str1); return 128; }
What am I doing wrong?
Is your function compiled using C or C++ bindings? You don’t specify, but it looks to me like there is a possibility that you are using the C++ compiler – the compiler uses very different name mangling from the C compiler and you will not be able to find the name ‘TestFunc’ as simply as if you were using the C compiler or using C name mangling rules.
To simply tell the C++ compiler to use C name mangling rules, use this in the header file: