Re: file delete routine is intermittent
- From: "Jonathan Wood" <jwood@xxxxxxxxxxxxxxxx>
- Date: Wed, 20 Apr 2005 11:09:58 -0600
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
.
- Follow-Ups:
- Re: file delete routine is intermittent
- From: MikeD
- Re: file delete routine is intermittent
- From: Karl E. Peterson
- Re: file delete routine is intermittent
- References:
- file delete routine is intermittent
- From: Steve Easton
- Re: file delete routine is intermittent
- From: MikeD
- Re: file delete routine is intermittent
- From: Jonathan Wood
- Re: file delete routine is intermittent
- From: MikeD
- file delete routine is intermittent
- Prev by Date: Re: file delete routine is intermittent
- Next by Date: Re: windows unstable
- Previous by thread: Re: file delete routine is intermittent
- Next by thread: Re: file delete routine is intermittent
- Index(es):
Relevant Pages
|