Page 1 of 1

problem

Posted: Thu Jan 19, 2012 9:51 pm
by morosh
I'm using TailBite to make a small personal library:

Code: Select all

Global resultsdll.s

ProcedureDLL.s removeextraspaces(str.s)
 
 resultsdll=str
 
 While FindString(resultsdll, "  ",1) > 0
   resultsdll=ReplaceString(resultsdll, "  ", " ") 
Wend
ProcedureReturn resultsdll
EndProcedure
and I tested it with the following code:

Code: Select all

Debug removeextraspaces2("aa                bbbbb               ccc")
Debug "aa bbbbb ccc"
It didn't work.

putting the procedure in the same file:

Code: Select all

Global resultsdll.s

Procedure.s removeextraspaces2(str.s) 
 resultsdll=str
 
 While FindString(resultsdll, "  ",1) > 0
   resultsdll=ReplaceString(resultsdll, "  ", " ") 
Wend
ProcedureReturn resultsdll
EndProcedure

Debug removeextraspaces2("aa                bbbbb               ccc")
Debug "aa bbbbb ccc"

works perfectly.

what's the problem?

Thank you

Re: problem

Posted: Thu Jan 19, 2012 10:09 pm
by Polo
Don't know about Tailbite but you've got one useless line: Global resultsdll.s :)

Re: problem

Posted: Fri Jan 20, 2012 2:39 am
by Bisonte
DLL and Returnstrings.... a lot of confusing...

I think, Tailbite have some issues, if your code is too small.
so only Compile this one function is useless...

If I make a Userlib, i made parts.
First the Init Part, the private part and then the public part.
the public and private part is really necessary if you want get a
string from your dll.

i hope you understand my text.

Code: Select all

; Init your DLL

EnableExplicit

ProcedureDLL YourLib_Init()
  Global ReturnString.s
EndProcedure
ProcedureDLL YourLib_End()
  ; here if you have something 
  ; to free up by yourself like FreeImage() etc.
EndProcedure

; the private functions...

Procedure.s pRemoveExtraSpace(String.s)
  
  While FindString(String, "  ",1) > 0
    String = ReplaceString(String, "  ", " ")
  Wend
  ProcedureReturn String
  
EndProcedure

; the public functions...

ProcedureDLL.s RemoveExtraSpace(String$) ; get rid of spaces
  ReturnString = pRemoveExtraSpace(String$)
  ProcedureReturn ReturnString
EndProcedure

Re: problem

Posted: Fri Jan 20, 2012 5:59 pm
by morosh
from the manual, it's written:

"Note about returning strings from DLL's:

If you want to return a string out of a DLL, the string has to be declared as Global before using it. "

Also, this is a small part from my lib

and last, this is no reply to my question

Re: problem

Posted: Sat Jan 21, 2012 12:52 am
by Bisonte
have you try this out ?

Here it worked... PB4.61b1(x86) and Tailbite 1.48

Re: problem

Posted: Sat Jan 21, 2012 2:20 am
by netmaestro
Here it worked... PB4.61b1(x86) and Tailbite 1.48
Yes, it works here too, same setup. It worked with Tailbite 1.46 too.

Re: problem

Posted: Sat Jan 21, 2012 8:19 am
by morosh
I just installed TailBite 1.4.8 and PureBasic4.61b1 (I have older versions), the problem remains.
My part of lib is:

Code: Select all

Global resultsdll.s
ProcedureDLL.s removeextraspaces(str.s)
 resultsdll=str
 
 While FindString(resultsdll, "  ",1) > 0
   resultsdll=ReplaceString(resultsdll, "  ", " ") 
Wend
ProcedureReturn resultsdll
EndProcedure
My test code is:

Code: Select all

Global resultsdll2.s

Procedure.s removeextraspaces2(str.s) 
 resultsdll2=str
 
 While FindString(resultsdll2, "  ",1) > 0
   resultsdll2=ReplaceString(resultsdll2, "  ", " ") 
Wend
ProcedureReturn resultsdll2
EndProcedure

Debug removeextraspaces2("aa                bbbbb               ccc")
Debug removeextraspaces( "aa                bbbbb               ccc")
Debug "aa bbbbb ccc"

; result:
;aa bbbbb ccc
;aa                bbbbb               ccc
;aa bbbbb ccc
using W7 x64 ultimate

Re: problem

Posted: Sat Jan 21, 2012 11:44 am
by Bisonte
I mean.... have you try my code ? This works... I am also on Win7 x64

Re: problem

Posted: Sun Jan 22, 2012 3:51 am
by lexvictory
Looking at the code, I do not see why it would not work, and if I'm not mistaken some have found it works?
Have you checked that the testing code (where you use the generated lib) is using the correct ASCII/Unicode mode? (i.e. the same as the lib was compiled with), or are you using the multilib mode?

Also, I advise you remove the global for the return string; it is NOT needed with TB, only with a DLL (Don't follow the DLL guidelines in the manual for TB, ProcedureDLL is only used to determine whether a Procedure is private/internal or public/external)