I have this dll written in PowerBasic, and I need to call it in PureBasic, but it giving me some trouble.
I found a tip to correct this.... call with type BSTR.
OK so far but....
Then the dll returns a string but i can't define a Prototype.p-bstr
A solution would be to change the return value to WSTRING....but that I can't change the export to WSTRING (if I do the native powerbasic program that calls the dll does not work correctly)
So I realy need a solution without making changes to the original dll.
Anyone with some tips ????
POWERBASIC dll source
Code: Select all
#COMPILE DLL "scrambler.dll"
#DIM ALL
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION SCRAMBLE(t AS STRING,sd AS LONG) EXPORT AS STRING
LOCAL tmp1&,scrambled$,s&,ln&,x&,v1$,v2$
RANDOMIZE sd
REPLACE ANY "|" WITH "!" IN t
t = REMOVE$(t, ANY CHR$(0))
ln& = LEN(t)
scrambled$ = STRING$(ln&,"|")
FOR tmp1& = 1 TO ln&
DO : s&=RND(1,ln&): LOOP WHILE MID$(t,s&,1) = "|"
x&=RND(1,255)
MID$(scrambled$,tmp1&,1) = CHR$(ASC(MID$(t,s&,1))XOR x&)
MID$(t,s&,1) = "|"
NEXT tmp1&
SCRAMBLE = scrambled$
END FUNCTION
'--------------------------------------------------------------------------------------------------------------------------------------------------------------
FUNCTION UNSCRAMBLE(t AS STRING,sd AS LONG) EXPORT AS STRING
LOCAL tmp1&,unscrambled$,s&,ln&,x&,v1$,v2$
RANDOMIZE sd
ln& = LEN(t)
unscrambled$=STRING$(ln&,"|")
FOR tmp1& = 1 TO ln&
DO: s&=RND(1,ln&): LOOP WHILE MID$(unscrambled$,s&,1) <> "|"
x&=RND(1,255)
MID$(unscrambled$,s&,1) = CHR$(ASC(MID$(t,tmp1&,1))XOR x&)
MID$(t,tmp1&,1) = "|"
NEXT tmp1&
UNSCRAMBLE = unscrambled$
END FUNCTION
PUREBASIC call
Code: Select all
OpenLibrary(0,"scrambler.dll")
Prototype.L ProtoFunction(Txt.p-bstr, Sd.l)
SCRAMBLE.ProtoFunction=GetFunction(0, "SCRAMBLE")
UNSCRAMBLE.ProtoFunction=GetFunction(0, "UNSCRAMBLE")
Td.s = SCRAMBLE("abcdefghijklmnopqrstuvwxyzABCEDEGHIJKLMNOPQRSTUVWXYZ",93235) ;---> error because function rreturns a number ?????
;Td.s = PEEKS(SCRAMBLE("abcdefghijklmnopqrstuvwxyzABCEDEGHIJKLMNOPQRSTUVWXYZ",93235)) ;---> error: invalid memory access
CloseLibrary(0)