在VB中调用C写的DLL崩溃,是哪出了问题?
C函数
AESDLL __stdcall AES_Init(int keySize, unsigned char *keyBytes)
{
SetNbNkNr(keySize);//初始化
memcpy(key,keyBytes,keySize);
//KeyExpansion();
// expand the seed key into a key schedule and store in w
}
VB声明
Private Declare Function AesInitial Lib "AES_DLL.dll " Alias "AES_Init " (ByVal keysize As Byte, keyBytes As Byte)
Dim KeyBuf(15) As Byte
调用
Call AesInitial(16, KeyBuf(0)) //传入第一个数组元素
单步执行到这的时候崩溃了。
[解决办法]
int keySize应申明为 ByVal keysize As long
而且Dim KeyBuf(15) As Byte中,应keybuf(15)=chr(0)
[解决办法]
晕!上面说的好象都不行吧!;
VB声明
Private Declare Function AesInitial Lib "AES_DLL.dll " Alias "AES_Init " (ByVal keysize As Byte, byval keyBytes As string)
Dim KeyBuf As string *15
调用
KeyBuf=string$(15,chr$(0)
Call AesInitial(16, KeyBuf )
'Vb 的字符串实际上就是 一个char 指针!只不过VB 没有指针概念,真正的其实VB 也有指针,只是不怎么提倡, varptr()函数得到的就是指针,address of 得到的是函数指针
大家如果有VB 调用VC DLL 方面的问题可以来问我!
我也研究这方面很长时间了,得到自己的心得!只要 VC 能调用的DLL ,VB 也可以调用
[解决办法]
Private Declare Sub AesInitial Lib "AES_DLL.dll " Alias "AES_Init " (ByVal keysize As Long, byval pkeyBytes As long)
Call AesInitial(16, varptr(KeyBuf(0))) 试试
Dim KeyBuf() As Byte
redim keybuf(15) 也试试