有关C#调用vc生成的dll时的问题
daizf 2003-03-27 04:22:21 我在vc中定义了两个导出函数,在别的vc工程中可以使用,但是在c#中却出现下面的错误,请问如何解决,谢谢
未处理的“System.DllNotFoundException”类型的异常出现在 WindowsApplication2.exe 中
其他信息:无法加载 DLL (dlltest1.dll)。
下面是部分代码:
class dlltemp
{
[DllImport("dlltest1.dll", EntryPoint="Add", SetLastError=true,CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern int Add(int a,int b);
[DllImport("dlltest1.DLL", EntryPoint="ShowString", SetLastError=true,CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern void ShowString();
}
执行时如下:
InitializeComponent();
MessageBox.Show(dlltemp.Add(1,2).ToString());
dlltemp.ShowString();