I think there's an error in this part.


; first, we need the filename in Unicode
invoke lstrlen, pszFileName
mov dwLength, eax ; <---------this is the original file name length
rol eax, 1 ; double eax
add eax, 2 ; allow for trailing zero
invoke CoTaskMemAlloc, eax
.IF !eax
; we didn't get the memory
invoke SetLastError, ERROR_NOT_ENOUGH_MEMORY
mov eax, NULL
ret
.ENDIF
mov pwszFileName, eax

invoke MultiByteToWideChar, CP_ACP, 0, pszFileName, -1, pwszFileName, dwLength ; <-----which gets passed to the function. According to the API reference, this is wrong, and it doesn't work for me.


I think it should be as follows:


; first, we need the filename in Unicode
invoke lstrlen, pszFileName
rol eax, 1 ; double eax
add eax, 2 ; allow for trailing zero
mov dwLength, eax ; <---------this will be the Unicode string length
invoke CoTaskMemAlloc, eax
.IF !eax
; we didn't get the memory
invoke SetLastError, ERROR_NOT_ENOUGH_MEMORY
mov eax, NULL
ret
.ENDIF
mov pwszFileName, eax

invoke MultiByteToWideChar, CP_ACP, 0, pszFileName, -1, pwszFileName, dwLength ; <-----which gets passed to the function. Now it works.


Or am I wrong?
Posted on 2003-02-05 18:10:01 by El_Choni
El_Choni,

Sorry to have been so slow to come back to you on this but I have had a lot to do recently. If you have found a bug in Ernie Murphy's code and you have a reliable fix for it, please publish it with some idea of what you have changed and why so it can be changed in the distribution.

Regards,

hutch@movsd.com
Posted on 2003-02-08 01:27:03 by hutch--
Well, I think that's what I've done exactly in my first post. The first code doesn't work, because the buffer length passed to MultiByteToWideChar is thet of the original string length, not that of the required string. The second puts the correct required buffer length in dwLength and it works as expected. I think it can't be more clear.
Posted on 2003-02-14 06:03:07 by El_Choni
cchWideChar
The size, in wide characters, of the buffer pointed to by the lpWideCharStr parameter. If this value is zero, the function returns the required buffer size, in wide characters, and makes no use of the lpWideCharStr buffer.

so dwLength is correct but if you say that it doesn't work then there's some other issue at hand :/
Posted on 2003-02-14 06:22:07 by Hiroshimator
Oh, I see... then I don't understand why I can't make it work (sorry for posting a false bug, anyway).
Posted on 2003-02-14 06:43:08 by El_Choni
could you post your code to the board maybe? There might be a bug in either the routine or your code.
Posted on 2003-02-14 07:24:54 by Hiroshimator
Ok, adding 1 to dwLength solved the whole thing. It must be a problem of terminating zeroes or something like that. Thanks for your help.
Posted on 2003-02-16 14:39:09 by El_Choni