DLL calling parameter default?

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

DLL calling parameter default?

Post by HPW »

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.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

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.
Hans-Peter

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

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

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Post by HPW »

Thanks for the explanation.
So we have to check the passed parameter first on nil.
Hans-Peter

Locked