请问需要把这个dll添加到C#工程的引用中吗?我在添加确定的时候出现错误: “.dll could not be added. This is not a valid assembly or COM component. Only assemblies with extension dll and COM components can be referenced."同时,我没有添加引用,只是添加了下面的代码: class Test { [DllImport("dll.dll")] public static extern int add(int x, int y); } 在调用的时候也出现错误,提示dll并没有被加载。这是什么问题?
[DllImport("XXX.dll")]
static extern bool Init(long iIndex, ref Byte[] config);//注意类型转换
COM的DLL呢?
http://www.cnblogs.com/virusswb/archive/2008/06/02/1212358.htmlc#调用c++写成的dll文件
http://www.cnblogs.com/virusswb/archive/2008/05/30/1210520.html
“.dll could not be added. This is not a valid assembly or COM component. Only assemblies with extension dll and COM components can be referenced."同时,我没有添加引用,只是添加了下面的代码:
class Test
{
[DllImport("dll.dll")]
public static extern int add(int x, int y);
}
在调用的时候也出现错误,提示dll并没有被加载。这是什么问题?
我的dll放在:“C:\WindowsApplication1\lib\dll.dll”
我的客户工程在:“C:\WindowsApplication1”
我的C#文件在:“C:\WindowsApplication1\Form1.cs”当我的导入代码时使用相对路径:[DllImport("..\\lib\\dll.dll")] 就会出现错误,dll不能被加载。我试了好几种相对路径都不行。但是当我写成绝对路径就是正确的,所以很奇怪。谁能提供一个正确地相对路径?