المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Problem with doublebyte chars in Japanese



C++ Programming
08-19-2010, 11:11 AM
Hi,

I have an editor in my application which has a find functionality implemented for it.The user will enter text in the editor and will try the Find option from menu.The problem is when I have n double byte characters(of japanese) in my text and say if I try to find an char or word which after the double byte chars then my search is displaced by n bytes.This issue happens only in japanese and the same application works fine in English.Going through the below blog which has a similar problem as that of mine I noticed that the problem is with the dependancy on ComCtrl 6 dll used in xp manifest theme.

http://www.insidercoding.com/post/2008/08/06/Visual-C2b2b-60-2b-XP-Manifest-3d3d-Problems.aspx
My application is also developed in vc6 and we use a manifest file for XP visual theme as below

</span span class="code-SummaryComment"version/spanspan class="code-keyword"="/spanspan class="code-keyword"1.0"/span span class="code-SummaryComment"encoding/spanspan class="code-keyword"="/spanspan class="code-keyword"UTF-8"/span span class="code-SummaryComment"standalone/spanspan class="code-keyword"="/spanspan class="code-keyword"yes"/spanspan class="code-SummaryComment"?/spanspan class="code-SummaryComment"> Merely an XP test. And I also cannot move my application to unicode. There are ASCII functions in my code.MFC by default supports MBCS.Even after placing _MBCS in project settings doesnt solve my problem. When I debug the below code I found the problem with lstrlen which is returning n chars extra for n double byte chars in my text to find.This happens only when I debug the code in japanese OS , the same works fine when I debug the same application in English OS.

static int FindStrPos( LPSTR lpSrc, LPSTR lpFind, BOOL bMatchCase )
{
LPSTR p;
int pos = -1, len;
char szFind[FIND_LEN];

LPSTR lpStr;

lstrcpy( szFind, lpFind);
if( !bMatchCase ) {
len = lstrlen(lpSrc)+1;
lpStr = (LPSTR)wwHeap_AllocPtr( hChunkWM,
(GMEM_MOVEABLE | GMEM_ZEROINIT), len );
if( lpStr ) {
_fmemcpy( lpStr, lpSrc, len );
_fstrupr( lpStr );
_fstrupr( (LPSTR)szFind );
p = _fstrstr( lpStr, (LPSTR)szFind );
if( p ) {
pos = p - lpStr;
}
wwHeap_FreePtr( hChunkWM, lpStr );
return( pos );
} else {
debug("Alloc failed compare case-sensitive");
}
}

p = _fstrstr( lpSrc, lpFind );
if( p )
pos = p - lpSrc;

return( pos );
}
I also used MBCS functions like _mbslen instead of lstrlen and _mbsstr instead of _fstrstr then _mbslen is returning accurate length in japanese and when while finding the difference between the search position and actual text pos the value of pos is again added with n bytes in japanese version for n double byte chars in Text.

I tried removing the manifest file as the unknown problem is with the dependancy of comcontrl dll version 6 for enabling Xp style but it is giving other problems in japanese.

Any suggestion would be helpful.

Thanks,

Satya
Today is a gift, that's why it is called the present.