读书人

C#调用C++ DLL运作某个函数(有文件创

发布时间: 2012-08-28 12:37:01 作者: rapoo

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);

读书人网 >C#

热点推荐