Subhobroto Sinha wrote:
Hello all

I corrected my last patch after replacing everything
C++ into C.

Great. It looks much better! There's just one last thing:


+    SHGetPathFromIDListA(This->pPidl,szTemp);
+    This->sPath=HeapAlloc( GetProcessHeap(), 0,(strlen(szTemp)+1)*sizeof(WCHAR));
+    dwBytesRead=(strlen(szTemp)+1);/*Just to hold the length of the string*/
+    MultiByteToWideChar(CP_ACP,0,szTemp,dwBytesRead,This->sPath,dwBytesRead);
+    TRACE("%s\n",debugstr_w(This->sPath));

The above code will calculate an incorrect length in some locales. You should use:


len = MultiByteToWideChar(CP_ACP,0,szTemp,-1,NULL,0);
HeapAlloc( GetProcessHeap(), 0,len*sizeof(WCHAR));
MultiByteToWideChar(CP_ACP,0,szTemp,-1,This->sPath,len);

The (commonly made) assumption that one WCHAR is at most two multichar bytes isn't correct.

Mike





Reply via email to