当前位置:编程学习 > C#/ASP.NET >>

VC写的DLL接口如何导入C#?

--------------------编程问答-------------------- 数据类型 方法名称  还有返回值  要同一的  VC有的C#没有的要进行数据的处理 --------------------编程问答-------------------- 查一查,数据类型对不对 --------------------编程问答-------------------- VC接口定义如下:
int DataWrite(unsigned int DataSone,unsigned char ciphertext[16]);

C#重写如下,写入的数据不对:

[DllImport("Secrypt.dll",CharSet=CharSet.Auto,SetLastError=true)]
public static extern int Secrypt_Ciphertext_DataWrite(int DataZone,byte[] ciphertext);

请大家帮忙查一下,那出问题了?

谢谢! --------------------编程问答-------------------- VC接口定义如下:
int DataWrite(unsigned int DataSone,unsigned char ciphertext[16]);

C#重写如下,写入的数据不对:

[DllImport("Secrypt.dll",CharSet=CharSet.Auto,SetLastError=true)]
public static extern int Secrypt_Ciphertext_DataWrite(int DataZone,byte[] ciphertext);

调用方式:  

         byte[] b = new byte[16];
         for (int i = 0; i < 16; i++)
         {
              b[i] = (byte)i;
         }

         int ok = Secrypt_Ciphertext_DataWrite(1,  b);
执行结果:
        ok=true;
       写入的数据不对 --------------------编程问答-------------------- 把CharSet=CharSet.Auto改为CharSet=CharSet.ANSI试试 --------------------编程问答-------------------- VC的int,和C#的int是一个概念吗?
int DataWrite
public static extern int
检查数据类型!!!
--------------------编程问答-------------------- dreamrising,
你好!
 
wince下没有CharSet=CharSet.ANSI --------------------编程问答-------------------- 网上有C++/VC++与c#的数据类型定义对比 --------------------编程问答-------------------- VC定义:
int Secrypt_DataRead(unsigned int DataZone,unsigned char ciphertext[16]);
C#导入
[DllImport("Secrypt.dll")]
public static extern int Secrypt_Ciphertext_DataRead(int DataZone, byte[] ciphertext);

该方法可以正确获取数据,但是写就不行,应该数据类型没有问题,奇怪! --------------------编程问答-------------------- 看下定义结构是否正确,一般都是这里的问题 --------------------编程问答-------------------- 定义结构?
该函数返回是正确的,就是写入的数据是不对的
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,