C语言的动态库在C#中如何声明及调用
抱朴守拙 2013-07-18 02:38:00 C的函数声明:
int __declspec(dllexport) __cdecl des_encrypt(unsigned char * des_key, unsigned char * des_data, int des_len, unsigned char * des_result);
用WIN8下VS2010开发WinForm程序,项目目标平台为x86,动态库声明如下:
[DllImport("des.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto)]
public static extern int des_encrypt(ref string des_key, ref string des_data, int des_len, ref string des_result);
调用:
string key = "12345678";
string mingw = textBox1.Text;
string miw = "";
int i = BankPayPublic.des_encrypt(ref key, ref mingw, mingw.Length, ref miw);
前几次运行时报“System.ExecutionEngineException”的异常,调试几次后现在每次都是“vshost32-clr2.exe停止工作”,急求解决方案,多谢!