Problems wrapping a dll

Blitz3D Forums/Blitz3D Programming/Problems wrapping a dll

bytecode77(Posted 2008) [#1]
hi!

i wanted to make a wrapper for this dll:
http://xprofan.com/xprofan/h/hashdll-5930-0.html


my decls file looks like this and works well with all hash algorithms. but somehow it won't work in some circumstances...
.lib "hash.dll"
CreateHash$(file$, algorithm$):"testit"


example:
;Only working in debug mode
Print "Hello world!"
RuntimEerror CreateHash("Test.txt", "MD5")
;Working!
RuntimEerror CreateHash("Test.txt", "MD5")


i just don't have a clue and i would be glad to receive some help :)


### This is my example you may try: http://www.dev-ch.de/upload/files/Devils%20Child/HashTest.zip


Sweenie(Posted 2008) [#2]
Most likely the calling convention...
If the dll uses the cdecl convention and blitz the stdcall convention the stack will be messed up.
You can usually tell if it's stdcall by the export name.
Should be "_testit@8" or something like that if it was using stdcall.


bytecode77(Posted 2008) [#3]
CreateHash$(file$, algorithm$):"testit@8"
CreateHash$(file$, algorithm$):"_testit@8"

both are not working because "Userlib function not found !?!"


Sweenie(Posted 2008) [#4]
No, what I meant was that since the exported function isn't named like that it's most likely using the cdecl calling convention meaning it won't work with Blitz3d.

A solution would be to make a wrapper in c++ that exports using the stdcall convention.
Not the ideal solution since you will end up with two dlls, the hash.dll and your wrapper dll.


bytecode77(Posted 2008) [#5]
oh my god...
is there any other solution, because i don't know how to make a wrapper using c++?
is it easy so i can ask anyone to do it without bothering?
would you do it :)?


Sweenie(Posted 2008) [#6]
Try if this one works... haven't been able to test it myself.(Don't have blitz3d on this computer)

http://www.svenberra.net/hashwrap.zip

you will need the hashes.dll file as well.


bytecode77(Posted 2008) [#7]
hey thanks for helping me out buddy :)
but on the other hand, it's not working.
Userlib function not found.

or am i doing something significantly wrong?

edit: what do you mean by "need 'hashes.dll' as well" ?
i placed your dll and your decls in my userlibs folder (B+)


Dreamora(Posted 2008) [#8]
its a wrapper DLL so the original library (hashes.dll) must be present as well, not only the wrapper dll


bytecode77(Posted 2008) [#9]
yeah right, Sweenie already mentioned that, but when i'm putting all these 3 files in my B+ userlibs folder, i still get "User lib function not found"...


Vertigo(Posted 2008) [#10]
Sometimes you need to have the .dll file in the same folder as the one you are executing from. For instance I have a mysql dll that will produce a userlib not found error if its not in the directory of blitz's bin or the exe directory i am compiling in. Even though its in the userlibs and even in system32 I have still had issues with some libs that have hard coded paths and the like... very odd I know, but try it out. Plus Im not sure what exactly it is you are doing with MD5's but there is plenty of md5 info and even demo code here on the site, you can do it all within blitz.


bytecode77(Posted 2008) [#11]
by planting everything in all possible directories (eg. Blitz+\bin and system32) it still returns the same error.


bytecode77(Posted 2008) [#12]
Sweenie, you did such a great job on your TokaMak wrapper. i guess it's a piece of cake to wrap the hash dll for me :)
it's not that i'm begging someone to do my work - please don't take it this way!


bytecode77(Posted 2008) [#13]
hm, tried do make a wrapper using FreeBasic
dim library as any ptr
dim hashfunc as function(file as string, algorithm as string) as string

library = dylibload("hashes")
hashfunc = dylibsymbol(library, "testit")
print hashfunc("Test.txt", "MD5")
dylibfree library

same crash as when trying it with bb :(


Sweenie(Posted 2008) [#14]
Hi.

Ok, took a closer look at this one and the readme makes no sense.
It does seem to be using stdcall afterall (might be a delphi dll or something)
I found an older version and according to that the declaration should look like this...

.lib "hashes.dll"
CreateHash$(filein$, algorithm$,fileout) : "testit"

Notice I don't declare 'fileout' as a string since the dll will output the hash to a new file if any value is supplied.
Just call it like this...

Print CreateHash$("test.txt","MD5",0)

If you want it to output the hash to a file just change the declaration like this...
.lib "hashes.dll"
CreateHash$(filein$, algorithm$,fileout$) : "testit"

and call it like this...

CreateHash$("test.txt","MD5","hashresult.txt")


bytecode77(Posted 2008) [#15]
Oh my gosh, this seems to work!!
and it works with no wrapper :)
i gotta test this out at home. thanks buddy ;)