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目录下的。
不知道我这是哪个步骤或者哪里有问题、?