Custom PB Lib question

Everything else that doesn't fall into one of the other PB categories.
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Custom PB Lib question

Post 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 :D (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.
FloHimself
Enthusiast
Enthusiast
Posts: 229
Joined: Wed May 14, 2003 3:38 pm
Location: Lüneburg - Germany

Post 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..
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post 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.
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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 ?
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post 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]
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Yes, please send it.
Seldon
Enthusiast
Enthusiast
Posts: 405
Joined: Fri Aug 22, 2003 7:12 am
Location: Italia

Post by Seldon »

Ok, thank you. I've just sent a ZIP archive to alphasnd@purebasic.com .
Post Reply