首页 新闻 会员 周边

C#调用C语言DLL

0
悬赏园豆:50 [待解决问题]

我调用一个 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?我是不是方法参数定义错了?

 

 

Hey Hitch的主页 Hey Hitch | 初学一级 | 园豆:106
提问于:2015-11-30 16:13
< >
分享
所有回答(1)
0

CI_RV是函数的返回结果,应该是结构还是啥?

http://www.cnblogs.com/2018/archive/2013/05/07/3064086.html 也可以使用这些工具

2012 | 园豆:21230 (高人七级) | 2015-11-30 16:18
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册