newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: HPW on March 07, 2004, 12:06:17 AM

Title: DLL calling parameter default?
Post by: HPW on March 07, 2004, 12:06:17 AM
Is there a default parameter with DLL calling?



> (setq mytest(get-string(hpwMimeEncodeString "")))

""

> (setq mytest(get-string(hpwMimeEncodeString "€")))

"gA=="

> (setq mytest(get-string(hpwMimeEncodeString nil)))

"gA=="



When I use nil or undefined symbol the DLL get a '€' (ASCII 128).

Is this a default or where does it come from.
Title:
Post by: Lutz on March 07, 2004, 05:07:14 AM
No, there is no default parameter, it all depends how your function 'hpwMimeEncodeString' is written and how much parameters you pass, if you don't pass the exact numbers and types the function is written for, the result is not defined. On Windows it is also necessary to compile for the correct calling conventions.



Lutz
Title:
Post by: HPW on March 07, 2004, 06:21:47 AM
The parameter is PChar and it is not a real problem.

I pass acidently a nil to it and wondered about the return-value.

When passing nil to the parameter,  I thought to get an empty string, but it was the '€'.

Maybe something which comes from delphi by default.
Title:
Post by: Lutz on March 07, 2004, 07:13:53 AM
Here is an explanation if you are interested in newLISP internals:



In case that you pass a parameter which is not an integer, float or string newLISP passes the ardress of the lisp cell. I you case the receiving imported routines took this address as a string pointer and the value the cell address was pointing to, happens to be "€" which is the lowest byte of the type word in the lisp cell.



You can simulate this by doing a:



(get-string nil) => "€"



or



(char (get-string nil) ) => 128



This is the type byte of the lisp cell nil



Lutz
Title:
Post by: HPW on March 07, 2004, 08:06:59 AM
Thanks for the explanation.

So we have to check the passed parameter first on nil.