On 23/01/2016 14:00, Nikolay Sivov wrote:
On 23.01.2016 15:47, Pierre Schweitzer wrote:
On 22/01/2016 09:58, Alexandre Julliard wrote:
Pierre Schweitzer pierre@reactos.org writes:
- ret = WNetUseConnectionW(hwndOwner, pRes, passW, userIDW, dwFlags,
accessNameW, lpBufferSize, lpResult);
- if (lpAccessName && lpBufferSize && *lpBufferSize && accessNameW)
- {
len = WideCharToMultiByte(CP_ACP, 0, accessNameW, -1, NULL, 0, NULL, NULL);
if (len && len <= *lpBufferSize)
WideCharToMultiByte(CP_ACP, 0, accessNameW, -1, lpAccessName, len, NULL, NULL);
- }
You need to handle failures, and a possibly different lpBufferSize for the W function. It could also use some test cases, which would probably require the W function to do something useful first.
Thanks for your review.
There's no need, in my understanding of MSDN of a different lpBufferSize. It contains the size in chars of the buffer. So, be it for A or W, we pass the same,
That's a wrong assumption. In this case you need to get length of W-buffer with WNetUseConnectionW() first, allocate buffer, call WNetUseConnectionW(), then convert W->A and at this point WideCharToMultiByte will return required A-buffer length that you can compare with WNetUseConnectionA argument value to check if passed buffer was large enough.
I'm not sure I understand your point. We're talking about a length in chars. So let's have a view on how my current implementation currently works. Let's say the caller calls A with a CHAR buf[256] and len = 256. This is legit: buffer can store 256 chars (including the null char). In my implementation, I take the len, and allocate a WCHAR buf[256]. And pass it with len, to W.
Two cases, buffer is big enough: W will write up to 256 chars in buf. When W is over, I can get the len in chars of the A string with the first WideCharToMultiByte. I don't see a reason why it should be higher than 256 (but in this case, I return an error - this is perhaps the case you don't like?). And then, I can write in the buffer, which is big enough to hold up to 256.
On the contrary, buffer is too small. Let's say, W wants to write 260 chars. It will write in len that it needs 260 chars, and return WN_MORE_DATA. Job done, that's what the A caller needs to know. It can then, recall with a CHAR buf[260].