我调用一个 C 语言编写的DLL
函数原型如下:
1 CI_SymEncrypt( 2 long nFunction, 3 unsigned char *pEntity, 4 unsigned char *pPlainData, 5 unsigned long nPlainLength, 6 unsigned char *pCipherData, 7 unsigned long *pnCipherLength 8 );
调用示例
#include “Custom_Interface.h” #include “GI_Datatype.h” #define reciveID “020000000008”//假设接收方ID为020000000008 #define sendID “020000000009”// 假设发送方ID为020000000009 void main() { CI_RV rv; unsigned long dataLen, encDataLen,newDataLen; unsigned char data[1024]; //假设明文最大长度为1024个字节 unsigned char encData[1024+16];//对应最大密文长度为1024+16个字节 unsigned char newData[1024];//假设解密得到的新明文长度最大为1024个字节 dataLen = 563;//假设加密的数据长度为563个字节 //使用与实体0008共享的第3个对称加密密钥加密将要与实体0008共享的数据。 rv = CI_SymEncrypt( 3, reciveID, data, dataLen, NULL, &encDataLen); if(rv != GI_OK) { printf(“get cipher length error. Error code is [%08x]\n”,rv); } }
然后我C#代码
1 [DllImport("XXX.dll", EntryPoint = "CI_SymEncrypt", CharSet = CharSet.Auto)] 2 public static extern Int32 CI_SymEncrypt(long nFunction, ref byte[] pEntity, ref byte[] pPlainData, int nPlainLength, ref byte[] pCipherData, ref int pnCipherLength);
程序运行没有报错,方法返回的code 说指针参数为NULL?我是不是方法参数定义错了?
CI_RV是函数的返回结果,应该是结构还是啥?
http://www.cnblogs.com/2018/archive/2013/05/07/3064086.html 也可以使用这些工具