ATL component Chinese path registration problem

zhaozj2021-02-08  271

ATL component Chinese path registration problem

I used ATL to write a COM component (MBCS compilation), if installed in the Chinese path, registration will fail. Why fail? Open ATL source file statreg.h, you can find the function BOOL AddString (LPColestr LPSZ) He was called by the UpdateRegistry, which called Bool Addchar (Const Tchar * PCH). The problem appears in these two functions.

See: BOOL AddString (LPCOLESTR lpsz) {! USES_CONVERSION; LPCTSTR lpszT = OLE2CT (lpsz); while (* lpszT) {AddChar (lpszT); lpszT ; // note @ 1} return TRUE;} BOOL AddChar (const TCHAR * PCH) {if (npos == nsize) // realloc @ 3 {nsize * = 2; p = (lptstr) CotaskMemRealloc (p, nsize * sizeof (tchar));} P [NPOS ] = * pch; #ifndef _unicularode IF (isdbcsleadbyte (* pch)) P [NPOS ] = * (PCH 1); file: // Note! @ 2 # endif return true;} When we don't use Unicode, if you encounter a Chinese word, mark @ 2 Understand the entire Chinese character, deposit into the buffer. But the PCH variable still points to the first byte of the Chinese character, return to @ 1 line, LPSZT points to the second byte of the Chinese characters! After the Chinese characters later The second byte is processed again as a separate character. So it has been garbled. (Causes a part of the information registered by the component is wrong) How to solve it? From the above analysis, it is easy to solve: BOOL AddString (LPColestr LPSZ) {USES_CONVERSION; LPCTSTR LPSZT = OLE2CT (LPSZ); While (* LPSZT) {addchar (lpszt); lpszt ;} return true;} / ************************************ ********************************************************** * This is a singer's singer's singer, \\ ********************************** ******* // ************************************************** *************************** BOOL AddChar (const tchar * pch) ************* *********************************************************** **** / BOOL Addchar (const tchar * & pch) file: // we'll modify the pch value {ix (npos == nsize) // realloc {nsize * = 2; p = (lptstr) cotaskmemrealloc (p, NSIZE * SIZEOF (TCHAR));} P [npos ] = * pch; #ifndef _unicode if (isdbcsleadbyte (* pch)) / ********************* ******************************************** P [NPOS ] = * (PCH 1);

转载请注明原文地址:https://www.9cbs.com/read-1869.html

New Post(0)