日期:2014-05-18  浏览次数:20933 次

C#调用C++ DLL运行某个函数(有文件创建/写入操作)时 程序直接关闭
C#调用C++ DLL运行某个函数(有文件创建/写入操作)时 程序直接关闭

C++ 函数定义
a(unsigned char *Oper)
{

FILE *fp;
int i;
  BYTE *ciphertext;
uchar key[]="12345678";
Des(Oper,key,ciphertext);
if ((fp=fopen(FileName,"w+b")) == NULL) return Err;
i = fwrite(ciphertext,8,1,fp);
fclose(fp);
if (i != 1) return Err;
return DAS_OK;
}

C# 引用后执行这个函数时,程序会自动关闭...
异常无法捕捉


------解决方案--------------------
c#函数参数用byte[]传过去就行了
[DllImport("xxx.dll")]
public static extern void OutputDebugString(byte[] Oper);