C#如何引用C++ dll的函数

C#代码如下:
public class Service1 : System.Web.Services.WebService
{

    [WebMethod]
    public string HelloWorld()
    {
        bool a = MES_UnInitEngine();
        return "Hello World";
    }

    [DllImport("MESEngine.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    private static extern bool MES_InitEngine(UInt16 strPath);

    [DllImport("MESEngine.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    private static extern bool MES_UnInitEngine();



}

C++代码如下:
#ifdef MES_EXPORTS
#define MES_API __declspec(dllexport)
#else
#define MES_API __declspec(dllimport)
#endif

// 定义导出的接口

/************************************************************************/
/* /
/
***********************************************************************/

/**

  • 系统初始化接口
  • @param strDataPath [in] 数据路径
  • @return 成功返回TRUE,失败返回FALSE / MES_API bool MES_InitEngine( WCHAR strPath );

/**

  • 系统释放接口
  • @return 成功返回TRUE,失败返回FALSE */ MES_API bool MES_UnInitEngine( );

最终由C++给到我这边的是一个dll文件,我试过以下操作:
1.在项目上直接引用该dll,但是提示“请确保此文件可访问并且是一个有效的程序集或COM组件”
图片说明
2.在运行中进行注册,但是提示
图片说明
3.在程序中直接使用DllImport进行引用,项目能够生成成功,不报错,但是在运行该方法的时候,却提示
图片说明

另外说一下,该DLL我是放在C盘的system32目录下的。
不知道我这是哪个步骤或者哪里有问题、?

你用的com dll方式加载的。而你的dll不是com组件。

你的系统是64bit的么?如果是64bit,要放在SysWoW64下,而不是System32下。

另外,你这是不同dll,所以用方法3。假设你的方法签名相符的话。