Cannot call DLL import entry in C# from C++ project. EntryPointNotFoundException
- by kriau
I'm trying to call from C# a function in a custom DLL written in C++. However I'm getting the warning during code analysis and the error at runtime:
Warning: CA1400 :
Microsoft.Interoperability : Correct
the declaration of
'SafeNativeMethods.SetHook()' so that
it correctly points to an existing
entry point in 'wi.dll'. The unmanaged
entry point name currently linked to
is SetHook.
Error:
System.EntryPointNotFoundException was
unhandled. Unable to find an entry
point named 'SetHook' in DLL 'wi.dll'.
Both projects wi.dll and C# exe has been compiled in to the same DEBUG folder, both files reside here. There is only one file with the name wi.dll in the whole file system.
C++ function definition looks like:
#define WI_API __declspec(dllexport)
bool WI_API SetHook();
I can see exported function using Dependency Walker:
as decorated: bool SetHook(void)
as undecorated: ?SetHook@@YA_NXZ
C# DLL import looks like (I've defined these lines using CLRInsideOut from MSDN magazine):
[DllImport("wi.dll", EntryPoint = "SetHook", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAsAttribute(UnmanagedType.I1)]
internal static extern bool SetHook();
I've tried without EntryPoint and CallingConvention definitions as well.
Both projects are 32-bits, I'm using W7 64 bits, VS 2010 RC.
I believe that I simply have overlooked something....
Thanks in advance.