Page 1 of 1
Custom PB Lib question
Posted: Fri Oct 24, 2003 2:02 pm
by Seldon
I've successfully converted 2 functions from a DLL of mine (written in C with LCC-Win32) to a static PB Lib and it works

(I still have to test carefully but it seems all fine). Since my 2 functions use standard C functions like sprintf(), atoi(), etc.. in the Lib description file (.desc) I wrote I'm using the Windows C runtime DLL (crtdll.dll). I wonder is that necessary ? Since all PB Exes import such DLL, maybe is it already loaded and I must not specify again that I use it ? Maybe it is a question definitely for Fred. Thank you in advance.
Posted: Fri Oct 24, 2003 3:42 pm
by FloHimself
Seems that the pbcompiler always link to crtdll.dll, so there is no need to declare it in the description file. I've never done so..
Posted: Fri Oct 24, 2003 5:04 pm
by Seldon
Thanks for your reply. Btw, I've found a weird problem in my LIB, I'll try to explain it to know what's wrong with it. Well.. basically I pass to my function a string pointer and a byte, like this:
extern _stdcall int PB_MyFunc(char *miastringa, BYTE mybyte)
{
// [...]
return 1;
}
Here it is the DESC file:
MyFunc, String, Byte
Long
In PB, I do:
a$="Ciao"
l.l=MyFunc(a$,4)
My C function works with the string buffer I pass and changes the content (actually it crypts the string appling an algorithm of linear math). Sometimes it can add from 1 to 3 bytes as well. The matter (and so the bug) is that if I do:
l.l=MyFunc(a$,4)
printn(a$)
It does print all OK, but if I do then:
b$=a$
printn(b$)
now and then (I've still to see when it happens exactly) a character -> chr(16) is added at the end of string. I tried to check the size of a$ and it gives the right result, while the size of b$ is ->len(a$)+1 , that is I got such chr(16) added.
The function is perfect (I use it in a DLL since monthes) so there's no problem there. What I don't understand why it doesn't happen always,
I guess it depends from the size of the string I pass, but why?? Have you some hints ? Thank you.
Regards.
PS: I've also tried to do a$=space(100) , but no luck. I could easily get rid of such bug doing:
b$=a$
if right(b$,1)=chr(16)
b$=Left(b$,Len(b$)-1)
endif
,but I'd like to know why it works bad.
Posted: Mon Oct 27, 2003 10:54 am
by Fred
Looks very very strange.. I don't happen any chr(16) characters. Try to print the string before to see if it's ok in PureBasic ?
Posted: Mon Oct 27, 2003 5:22 pm
by Seldon
Thanks Fred for reply. Yes, it's very weird. The strangest thing is that if I put the SAME code in the middle of another program, the chr(16) is not added

Besides, if I remove the line r$=Input() , chr(20) is added instead of chr(16) :roll:
Here it is the sample code I use (as you can see, I soon print the string processed by my custom function. The 1st time is fine, then I copy it into another string and such 2nd string contains that chr(16).
Code: Select all
OpenConsole()
a$="Prova12345"
PrintN(Str(Len(a$)))
e=EncodeEx(a$,4) ;my encrypt function
PrintN(Str(e))
PrintN(a$+" "+Str(Len(a$)))
r$=Input()
yy$=a$
PrintN(yy$+" "+Str(Len(yy$)))
If Right(yy$,1)=Chr(16)
yy$=Left(yy$,Len(yy$)-1)
EndIf
PrintN(yy$+" "+Str(Len(yy$)))
e=DecodeEx(yy$,4) ;decrypting function
PrintN(Str(e))
PrintN(yy$)
r$=Input()
End
If you want, I can send you my custom Lib, so you can test it.
[/code]
Posted: Mon Oct 27, 2003 10:26 pm
by Fred
Yes, please send it.
Posted: Tue Oct 28, 2003 9:03 am
by Seldon
Ok, thank you. I've just sent a ZIP archive to
alphasnd@purebasic.com .