本文介绍了VB6 - 使用指针声明和调用 C DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have an old C DLL I use to call from Ruby, but now I need to call it from VB6 and I can't figure out the correct way to do so.

Here is the header for the function I need:

int Decrunch(const BYTE *src, BYTE *dest, DWORD src_length)

*src is a sequence of bytes which will be decrypted by the function

*dest is a buffer which will recieve the decrypted data. I can call the function with dest=NULL and it will return the size of the decrypted data, so I can use it to create the buffer with the correct size.

I tried to declare it with both src and dest as Strings (like I do in Ruby) but it won't work. I've also tried to declare them as Byte and pass the first element of a byte array as I was pointed by some tutorials, but I think I didn't do it correctly.

Can someone help me with this?

Thank you!

解决方案

Air code

Private Declare DecrunchGetLength Alias "Decrunch" Lib "somedll.DLL" (ByRef src As Byte, ByVal nullptr As Long, ByVal SrcLength As Long) As Long

Private Declare Decrunch Alias "Decrunch" Lib "somedll.DLL" (ByRef src As Byte, ByRef dest As Byte, ByVal SrcLength As Long) As Long

Dim destLen As Long
 Dim src(0 To 9) As Byte
Dim dest() As Byte

' get bytes into src somehow

' get dest length
destLen = DecrunchGetLen( src(0), 0, 10)

ReDim dest(0 To destLen - 1)
destLen = Decrunch( src(0), dest(0), 10)

Useful links

这篇关于VB6 - 使用指针声明和调用 C DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 21:06
查看更多