http://bugs.winehq.org/show_bug.cgi?id=8511
Summary: DragQueryFile returns wrong string length Product: Wine Version: 0.9.33. Platform: Other OS/Version: other Status: UNCONFIRMED Severity: normal Priority: P2 Component: wine-shell32 AssignedTo: wine-bugs@winehq.org ReportedBy: hadrien-wine@psydk.org
Hi,
A friend of mine tried to run a win32 software I made, which relies on drag-and-drop features. My software is currently not working on Wine. We tracked the problem down to the DragQueryFileW function.
Here is a reminder of the declaration: UINT DragQueryFileW(HDROP hDrop, UINT iFile, LPWSTR lpszFile, UINT nBufferSize);
To get the needed length to store the file path, I call this function with lpszFile set to NULL:
UINT nNeededLength = DragQueryFileW(hDrop, iFile, NULL, 0);
nNeededLength is the total number of characters, not including the terminating null character, as stated by the function documentation in MSDN.
Then I call the function again with a dynamically allocated buffer: UINT nRet = DragQueryFileW(hDrop, iFile, pszFilePath, nNeededLength + 1);
The "+ 1" is because DragQueryFileW expects a buffer size that counts the terminating null character. The return value, nRet, is equal to nNeededLength on a real Windows.
On Wine 0.9.33 instead, we get the expected length + 1. I made a test I ran on Windows 2000 then on Wine 0.9.33 that confirms the unexpected behavior.
By looking at Wine source code it looks like the same problem exists with DragQueryFileA and DragQueryFile16 in shell.c and shellole.c
A possible test case in a WM_DROPFILES handler:
wchar szSuperBuffer[260]; UINT nFile = 0; UINT nLengthNeeded = DragQueryFileW(hDrop, nFile, NULL, 0); UINT nRet = DragQueryFileW(hDrop, nFile, szSuperBuffer, sizeof(szSuperBuffer)); UINT nLengthGot = strlenW(szSuperBuffer); if( !(nLengthNeeded == nRet && nLengthNeeded == nLengthGot)) { // ERROR ! (message box, error trace, or whatever) }