Рабочий код в 9-й версии:
Код: Выделить всё
Const RHASH_CRC32 = &H01
Const RHASH_MD5 = &H04
Const RHASH_TTH = &H20
Const RHPR_BASE32 = &H3
Const RHPR_UPPERCASE = &H8
Function GetTTH(filename)
Dim LibFileName, hLibModule, res
Dim digest(64), output(130), size, strTTH
Sys.DynAPI.CallType = 1
sys.dynapi.curbuf=0: sys.dynapi.setbuf(digest)
sys.dynapi.curbuf=1: sys.dynapi.setbuf(output)
LibFileName = sys.path & "librhash.dll"
hLibModule = Sys.API.LoadLibrary(LibFileName)
if hLibModule > 0 then
Sys.DynAPI.CallFunction hLibModule, "rhash_library_init"
if Sys.DynAPI.CallFunction(hLibModule, "rhash_file", RHASH_TTH, filename, sys.dynapi.ptrbuf(0)) < 0 then
GetTTH = ""
else
size = Sys.DynAPI.CallFunction(hLibModule, "rhash_get_digest_size", RHASH_TTH)
Sys.DynAPI.CallFunction hLibModule, "rhash_print_bytes", sys.dynapi.ptrbuf(1), sys.dynapi.ptrbuf(0), size, RHPR_BASE32 + RHPR_UPPERCASE
Sys.DynAPI.GetBuf strTTH, 1
Sys.API.FreeLibrary(hLibModule)
GetTTH = Sys.Conv.Buf2Txt(strTTH)
end if
else
GetTTH = ""
end if
End Function
Неудачная попытка переделки под 10.0.0.7600 версию:
Виснет после вызова rc = DllCall("", fn, RHASH_TTH, filename, digest.ptr), т.к. msgbox "проверка" - не выводится
Код: Выделить всё
Const RHASH_CRC32 = &H01
Const RHASH_MD5 = &H04
Const RHASH_TTH = &H20
Const RHPR_BASE32 = &H3
Const RHPR_UPPERCASE = &H8
Function GetTTH(filename)
Dim LibFileName, hLibModule, res, fn, rc
Dim digest, output, size, strTTH
Set digest = sys.newbuf(array("size = 65"))
Set output = sys.newbuf(array("size = 131"))
LibFileName = sys.path & "librhash.dll"
hLibModule = Sys.API.LoadLibrary(LibFileName)
if hLibModule > 0 then
fn = Sys.API.GetProcAddress(hLibModule, "rhash_library_init")
rc = DllCall("", fn)
fn = Sys.API.GetProcAddress(hLibModule, "rhash_file")
rc = DllCall("", fn, RHASH_TTH, filename, digest.ptr)
msgbox "проверка"
if rc < 0 then
GetTTH = ""
else
fn = Sys.API.GetProcAddress(hLibModule, "rhash_get_digest_size")
size = DllCall("", fn, RHASH_TTH)
fn = Sys.API.GetProcAddress(hLibModule, "rhash_print_bytes")
rc = DllCall("", fn, output.ptr, digest.ptr, size, RHPR_BASE32 + RHPR_UPPERCASE)
Sys.API.FreeLibrary(hLibModule)
GetTTH = Sys.Conv.Ptr2Str(output.ptr)
end if
else
GetTTH = ""
end if
End Function