Library functions buggy? [solved]

Linux specific forum
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Library functions buggy? [solved]

Post by Kukulkan »

Hi,

I have a linux .so library available that surely works in my linux system. I use the following code examples with the latest PureBasic V4.10 for Linux:

Code: Select all

; #########################################
; Example 1: This works fine (in the first moment)
; #########################################

#CryptLibrary = 0

If OpenLibrary(#CryptLibrary, "libcryptosysapi.so")
  ; ok
  strMessage.s = "Testmessage"
  strDigest.s = Space(64)
  Ret.l = CallFunction(#CryptLibrary, "SHA2_StringHexHash", @strDigest.s, @strMessage.s)
  Debug "Message: " + strMessage.s
  Debug "Hash   : " + strDigest.s
  CloseLibrary(#CryptLibrary)
EndIf

; #########################################
; Example 2: invalid memory access on marked position
; #########################################

; Sub-Procedure
Procedure.s CalcHash(strToHash.s)
  strDigest.s = Space(64)
  Ret.l = CallFunction(#CryptLibrary, "SHA2_StringHexHash", @strDigest.s, @strToHash.s)
  Debug "Message: " + strToHash.s
  Debug "Hash   : " + strDigest.s
  ProcedureReturn strDigest.s ; <<<< INVALID MEMORY ACCESS
EndProcedure

; Main Program
If OpenLibrary(#CryptLibrary, "libcryptosysapi.so")
  ; ok
  Hash.s = CalcHash("Testmessage")
  CloseLibrary(#CryptLibrary)
EndIf
The first example works. The second example fails with an invalid memory access at the marked position. But much more weird: Looking at the debug output, the second example switches the results of Message and Hash! In the windows version this example works fine (simply replaced libcryptosysapi.so with diCryptoSys.dll)!

Is it my misstake or is there a bug in such essential function?

Kukulkan
Last edited by Kukulkan on Mon Mar 03, 2008 11:21 am, edited 1 time in total.
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Post by walker »

try CallCFunction instead of CallFunction....
I guess, as most of the shared libs are C-style librarys , you should call it appropriate :wink:
User avatar
Kukulkan
Addict
Addict
Posts: 1396
Joined: Mon Jun 06, 2005 2:35 pm
Location: germany
Contact:

Post by Kukulkan »

Thank you! Now it works!

Kukulkan
Post Reply