"AS ASCIIZ [* number]" parameters are always passed as the address of the variable used in the call, unless a literal null ("") is passed in which case zero is passed by value.
The " * number" is used by the compiler to limit the number of bytes it will read or write to that parameter (and also is checked against the size of the passed variable).
If you use an ambiguous-length parameter ( no "* number") the compiler will read until the first null - or until you no longer own the memory, at which point a protection fault will ensue - and will attempt write as many bytes as you tell it to and append a trailing zero, assuming you have passed a variable with sufficient size to hold the assigned bytes. If your passed variable is not long enough, the compiler will write anyway until a protection fault ensues. If that write overwrites other memory you own it will just keep on writing and will corrupt that memory.
Using fixed-length or ambiguous-length ASCIIZ parameters is "programmer's option."
MCM
Announcement
Collapse
No announcement yet.
Shell using long file name in DOS program
Collapse
X
-
I have the current 8.04.0042 and 4.04.0042.
Is leaving the length out okay since passing an ASCIIZ is a pointer?
Leave a comment:
-
>Should ASCIIZ parameter receiving a passed value have a length?
That depends on which version of the compiler you are using. Ambiguous length (no "* number" ) ASCIIZ parameters were not supported until 7x.
Leave a comment:
-
Does ASCIIZ string need a length if accepting value?
Should ASCIIZ parameter receiving a passed value have a length?
FUNCTION ShortPath(LongPath AS ASCIIZ) AS STRING
FUNCTION ShortPath(LongPath AS ASCIIZ * 260) AS STRING
Code:DECLARE FUNCTION GetShortPathName LIB "KERNEL32.DLL" ALIAS "GetShortPathNameA" _ (lpszLongPath AS ASCIIZ, _ lpszShortPath AS ASCIIZ, _ BYVAL cchBuffer AS LONG) AS LONG DECLARE FUNCTION ShortPath(LongPath AS ASCIIZ) AS STRING %MAX_PATH = 260 FUNCTION PBMAIN AS LONG LOCAL z AS ASCIIZ * %MAX_PATH z = "c:\program files\" ? ShortPath(z) SLEEP 1000 END FUNCTION FUNCTION ShortPath(LongPath AS ASCIIZ) AS STRING 'Is LongPath a pointer to the value passed since it doesn't need a length? LOCAL zResult AS ASCIIZ * %MAX_PATH GetShortPathName LongPath, zResult, BYVAL SIZEOF(zResult) FUNCTION = zResult END FUNCTION
Leave a comment:
-
Afaik there is an interupt for that.
I also believe you can get the filename by using some dos command like dir(filename) ot similar.
Leave a comment:
-
Shell using long file name in DOS program
Are these always the same?
If not, can DOS program only get short name using Windows API function?
org$ = "c:\program files\something\something.exe"
org$ = "c:\progra~1\something\something.exe"Tags: None
Leave a comment: