Re: file delete routine is intermittent



MikeD,

> > This is not necessary as Visual Basic automatically appends a single
null
> > terminator character to every string.
>
> Only when you pass a string as a parameter (and pass it ByVal). In this
> case, you're passing a structure. VB does NOT automatically append a null
> character to string members of structures so you must append the null
> character yourself. I'm very surprised you weren't aware of that.

Virtually every API function uses the C standard of having strings
terminated with a null character. Therefore, strings within structures being
passed to Windows would not work unless you manually appended the
terminator. After years of passing structures to Windows, I can tell you
with confidence that this is not necessary.

I browsed the file VB4DLL.TXT that ships with Visual Basic. In section 4, it
includes the following items:

"Visual Basic maintains variable-length strings internally as BSTRs.
BSTRs are defined in the OLE header files as OLECHAR FAR *. An
OLECHAR is a UNICODE character in 32-bit OLE and an ANSI character in
16-bit OLE. A BSTR can contain NULL values because a length is also
maintained with the BSTR. BSTRs are also NULL terminated so they can
be treated as an LPSTR."

and in section 5 it includes an example of passing a UDT to a DLL and does
not manually append a terminator.

What is your information based on?

> Not necessarily. UnderWin95/98, the function works fine if you don't
append
> a null character at all (let alone 2). This has nothing to do with VB.
It
> has everything to do with Win95/98 not being as strict for some API
> functions. Under any NT-based version of Windows, the function is
> considerably stricter and if you don't have the double null-termination,
the
> function is unpredictable. It may not delete any files, it may delete a
> wrong file, it may delete multiple files (for the FO_DELETE action). At
> least, this has been my experience.

Maybe I wasn't clear. I was not talking about VB. I was talking about how
SHFileOperation knew when it found the last file. If the double-terminator
was missing, it wouldn't know it found the last filename and so would
continue searching the input string for another filename. My point was that,
in this case, it would not miss any of the files specified (as described by
the OP). Instead, it would probably get some sort of memory violation as it
went past the end of the string, looking for additional filenames.

--
Jonathan Wood
SoftCircuits
http://www.softcircuits.com
Available for consulting: http://www.softcircuits.com/jwood/resume.htm


.



Relevant Pages

  • Re: file delete routine is intermittent
    ... >>> terminator character to every string. ... >> Only when you pass a string as a parameter. ... >> character to string members of structures so you must append the null ...
    (microsoft.public.vb.winapi)
  • Re: file delete routine is intermittent
    ... > This is not necessary as Visual Basic automatically appends a single null ... > terminator character to every string. ... Only when you pass a string as a parameter. ...
    (microsoft.public.vb.winapi)
  • Re: Append characters to file name to establish uniqueness
    ... I am trying to keep a set of files online and append a character ... string to each file in order to establish uniqueness to each file name ...
    (comp.os.vms)
  • Re: Pound symbol in a string
    ... > When I use system.IO.StreamWriter to write append a string to file that ... > contains the GBP pound symbol, I notice that it also appends an extra ... Yet when I examine the string character ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Unicode: ugh!
    ... a string is defined as a pointer to char in the ... by and including the first null character. ... the null terminator is not a NULL character (NULL ...
    (comp.lang.c)