求改写一个函数

闭着眼刷牙 2013-05-28 05:07:22
我的dll是有c++生成的 现在要被vb6调用测试,第一次自己做了一个报错哪位帮我看看
c语言的
void sha2_hmac( const unsigned char *key, size_t keylen,
const unsigned char *input, size_t ilen,
unsigned char output[32], int is224 );

我改写的vb
public declare Function sha2_hmac Lib ".\sha2.dll"(ByVal key(5) As Byte, ByVal keyLen(5) As Integer, ByVal input(5) as Byte, ByVal intputLen(5), ByVal is224 as Integer)

...全文
136 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 3 楼 Tiger_Zhao 的回复:
不能在类/窗体/控件中 Public Declare,改为 Private Declare,或者声明在模块中。
我已经声明在模块里了 现在主要是调用函数老报错 你能不能帮我把这个c的函数改写成VB6可以用的 谢谢啦
看着捉急 2013-05-30
  • 打赏
  • 举报
回复
不会vb
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 13 楼 worldy 的回复:
不会有问题,output为空,是否是你的c函数内部没有给output数据? 你按正常调用,先给s1.l1,s2,l2 赋值,再调用?另外,你最后一个参数怎么是0?按照一般做法,最后那个数据应该是指示c函数,output有多少个字节,为不知道你的函数也是这个意思。你试试将最后一个参数设置不是0调用看看
最后一个参数作为标志位 用0和非0表示, 这个dll我已经用asp.net调用测试成功了。我自己再试试 非常感谢你的帮助
worldy 2013-05-30
  • 打赏
  • 举报
回复
那个函数定义为sub,没有给别的变量赋值,因此,不需要括号,加括号会语法错误
worldy 2013-05-30
  • 打赏
  • 举报
回复
不会有问题,output为空,是否是你的c函数内部没有给output数据? 你按正常调用,先给s1.l1,s2,l2 赋值,再调用?另外,你最后一个参数怎么是0?按照一般做法,最后那个数据应该是指示c函数,output有多少个字节,为不知道你的函数也是这个意思。你试试将最后一个参数设置不是0调用看看
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 11 楼 worldy 的回复:
漏看了两个参数: void sha2_hmac( const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); ==> private declare sub sha2_hmac lib ".\sha2.dll" sha2_hmac(byval string key,byval keylen as long,byval input as string,byval ilen as long,output as byte,byval is224 as long) 调用: Dim output(32) As Byte Dim s1 As String, s2 As String Dim L1 As Long, L2 As Long sha2_hmac s1,l1,s2,l2,output(0),0 '参数不用先赋值?
要参数,要赋值的 可是我初始化后没有 输出结果output为空 是不是数据类型output有问题 你这个函数与后边参数不加括号吗?
worldy 2013-05-30
  • 打赏
  • 举报
回复
漏看了两个参数: void sha2_hmac( const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); ==> private declare sub sha2_hmac lib ".\sha2.dll" sha2_hmac(byval string key,byval keylen as long,byval input as string,byval ilen as long,output as byte,byval is224 as long) 调用: Dim output(32) As Byte Dim s1 As String, s2 As String Dim L1 As Long, L2 As Long sha2_hmac s1,l1,s2,l2,output(0),0 '参数不用先赋值?
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 8 楼 worldy 的回复:
你先试我给你的声明,看会不会“函数入口点”错误,如果不会,那就是有export,为给你的声明应该是对的,但是,调用必须是 dim s1 as string,s2 as string dim L1 as long,L2 as long sha2_hmac s1,l1,s2,l2
我按照你的调用 可是结果
Public Declare Sub sha2_hmac Lib ".\sha2.dll" (ByVal key As String, ByVal keylen As Long, ByVal inputt As String, ByVal ilen As Long, ByVal output As String, ByVal iss224 As Long)

底下是调用函数
[code=vb]
Dim output(32) As Byte
Dim s1 As String, s2 As String
  Dim L1 As Long, L2 As Long
  sha2_hmac( s1,l1,s2,l2, output, 0)
[/code] 提示syntax error不知道哪里有问题
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 8 楼 worldy 的回复:
你先试我给你的声明,看会不会“函数入口点”错误,如果不会,那就是有export,为给你的声明应该是对的,但是,调用必须是 dim s1 as string,s2 as string dim L1 as long,L2 as long sha2_hmac s1,l1,s2,l2
这是导出文件
#ifndef TestDll_H_
#define TestDll_H_

#ifdef MYLIBDLL
#define MYLIBDLL extern "C" _declspec(dllimport)
#else
#define MYLIBDLL extern "C" _declspec(dllexport)
#endif

//MYLIBDLL int Add(int plus1, int plus2);

MYLIBDLL void sha2( const unsigned char *input, size_t ilen,
           unsigned char output[32], int is224 );

/**
 * \brief          Output = SHA-256( file contents )
 *
 * \param path     input file name
 * \param output   SHA-224/256 checksum result
 * \param is224    0 = use SHA256, 1 = use SHA224
 *
 * \return         0 if successful, or POLARSSL_ERR_SHA2_FILE_IO_ERROR
 */
MYLIBDLL int sha2_file( const char *path, unsigned char output[32], int is224 );

MYLIBDLL void sha2_hmac( const unsigned char *key, size_t keylen,const unsigned char *input, size_t ilen,unsigned char output[32], int is224 );

MYLIBDLL  int sha2_hmac_file(const unsigned char *key, size_t keylen,const char *path, unsigned char output[32], int is224);
#endif
这是def文件
LIBRARY "SHA2DLL"
EXPORTS
 sha2_hmac @1
 sha2_hmac_file @2
 sha2 @3
 sha2_file @4
worldy 2013-05-30
  • 打赏
  • 举报
回复
你先试我给你的声明,看会不会“函数入口点”错误,如果不会,那就是有export,为给你的声明应该是对的,但是,调用必须是 dim s1 as string,s2 as string dim L1 as long,L2 as long sha2_hmac s1,l1,s2,l2
闭着眼刷牙 2013-05-30
  • 打赏
  • 举报
回复
引用 6 楼 worldy 的回复:
void sha2_hmac( const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); private sub sha2_hmac lib ".\sha2.dll" sha2_hmac(byval string key,byval keylen as long,byval input as string,byval ilen as long) 但是lz的这个函数似乎不是dll的export函数吧?
为什么这么说? 求专注 求指导
worldy 2013-05-30
  • 打赏
  • 举报
回复
void sha2_hmac( const unsigned char *key, size_t keylen, const unsigned char *input, size_t ilen, unsigned char output[32], int is224 ); private sub sha2_hmac lib ".\sha2.dll" sha2_hmac(byval string key,byval keylen as long,byval input as string,byval ilen as long) 但是lz的这个函数似乎不是dll的export函数吧?
Tiger_Zhao 2013-05-29
  • 打赏
  • 举报
回复
不能在类/窗体/控件中 Public Declare,改为 Private Declare,或者声明在模块中。
闭着眼刷牙 2013-05-29
  • 打赏
  • 举报
回复
constants, fixed-length strings,arrays, user-defined types and declare statements not allowed as public menbers of object modules 提示这句什么意思?
闭着眼刷牙 2013-05-28
  • 打赏
  • 举报
回复
这个也报错 哪里不对?
public declare Function sha2_hmac Lib ".\sha2.dll" (ByVal key(0 to 5) As Byte, ByVal keyLen(0 to 5) As Integer, ByVal input(0 TO 5) as Byte, ByVal intputLen(0 to 5), ByVal is224 as Integer) as Variant

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧