Problem with Access-mdb/DAO

Andreas Mohr andi at rhlx01.fht-esslingen.de
Tue Dec 16 10:06:17 CST 2003


Hi,

On Tue, Dec 16, 2003 at 04:10:36PM +0100, Fabian Cenedese wrote:
> 
> >I think I found an error in SysStringLen. Why? Because my application
> >started to work a lot better. Why not? I don't know if this is the right fix
> >or other stuff is involved (as with the GetWindowLong).
> >
> >     * The length of the string (in bytes) is contained in a DWORD placed
> >     * just before the BSTR pointer
> >     */
> >    bufferPointer = (DWORD*)str;
> >    bufferPointer--;
> >    return (int)(*bufferPointer/sizeof(WCHAR));
> >
> >If I come here with a string like "Nodes" (normal string length 5) it will
> >return (int)(5/2)=2. But 2 is definitely not enough (in WCHAR length). But
> >if I do (int)((5+1)/2)=3 my name comes through. And also the other names
> >that got truncated. So I would change it to:
> >
> >    return (int)((*bufferPointer+1)/sizeof(WCHAR));
> >
> >Can anybody comment on this? Is this the right fix?
> 
> Actually MSDN says about SysStringLen:
> 
> Return Value: The number of characters in bstr
> Comments: For a BSTR allocated with Sys[Re]AllocStringLen or SysAllocStringByteLen, this function always returns the number of characters specified in the cch parameter at allocation time
> 
> So this code looks strange. Either it should return *bufferPointer if
> not zero or then a real calculation _fstrlen(str)/sizeof(WCHAR).
> Or is MSDN wrong in this case?
Since SysAllocStringLen computes the amount of bytes needed for a given
length of WCHAR characters, the DWORD before the string probably always should
indicate twice as much as the string length for a WCHAR string.
(I guess the DWORD before the string is to be seen strictly internal, right?)
If you have a string like "Nodes", then the BSTR DWORD value should be
5*sizeof(WCHAR) == 5*2 == 10, *NOT* 5.

In other words, we don't have an even/odd division problem, but rather a
problem with the string length, since it should have been twice as much.

Please try to find out which function created that BSTR with this wrong
length calculation and try to fix it.

Thanks for your debugging!!

Andreas Mohr



More information about the wine-devel mailing list