It looks basically correct. Try to explicitly specify naming convention on both sides, for example
__cdecl
in C++ and
CallingConvention
equals to
CallingConvention.Cdecl
in
System.Runtime.InteropServices.DllImportAttribute
.
I would also advice to explicitly name entry point by using
System.Runtime.InteropServices.DllImportAttribute.EntryPoint
. In this way, you don't have to use
extern "C"
and bind the entry point even if the name is decorated or
mangled
(
http://en.wikipedia.org/wiki/Name_mangling[
^]). To see what the actual names are, use some binary dump utility like
DUMPBIN.EXE
, which is bundled with all versions of Visual Studio; you can use it from Visual Studio Command Prompt. See
http://msdn.microsoft.com/en-us/library/c1h23y6c%28v=vs.71%29.aspx[
^].
Also, I want to note that you use console in your sample DLL code but test it with Windows .NET application where the console is not shown by default. To show console, don't change anything in the project but application type. Set it to "Console Application" in the project Properties — your application will work as console and window application at the same time.
—SA