c#调用c的dll 遇到的字符串问题! 知道的进 内详 谢谢
原来的DES是
master_key:主密钥的BCD码
inputbuf:要加密的8位数据,不足位数后补'\0'
outputbuf:加密后得到的密文
void DES(char *key,char *s_text,char *d_text)
{
des_key_schedule sch;
des_set_key((des_cblock *)key,sch);
des_ecb_encrypt((des_cblock *)s_text,(des_cblock *)d_text,&(sch[0]),1);
}
为了给c#调用 主要为了返回d_text改成*d_text 我改成
void DES(char *key,char *s_text,char **d_text)
{
des_key_schedule sch;
des_set_key((des_cblock *)key,sch);
des_ecb_encrypt((des_cblock *)s_text,(des_cblock *)(*d_text),&(sch[0]),1);
}
c#里调用
[DllImport("testdll.dll",EntryPoint="DES",CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]
public static extern void DES(string key,string s_text,ref string d_text);
string returnValue=new string("");
DES("12345678","12345678",ref returnValue);
textBox1.text=returnValue;
但取出来的是8位中文乱吗
我直接用tc跑 把结果 %c打出来
是8个特殊字符
2种不一样
是不是哪里的编码错了 还是char 不能用string 调用
谢谢大家了