Problem with doublebyte chars in Japanese
-
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="wm"
type="win32"/>
<description>Merely an XP test.</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>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;
lstrc
-
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
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
version="1.0.0.0"
processorArchitecture="X86"
name="wm"
type="win32"/>
<description>Merely an XP test.</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentAssembly>
<assemblyIdentity
type="win32"
name="Microsoft.Windows.Common-Controls"
version="6.0.0.0"
processorArchitecture="X86"
publicKeyToken="6595b64144ccf1df"
language="*"
/>
</dependentAssembly>
</dependency>
</assembly>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;
lstrc
-
I dont understand your problem point yet. Will you explain the point for short again? :confused:
Sure .. say with a text having 6 double byte chars as below and if I try to find word My then my search is displaced by 6 chars and the pos is returned at "th" " DIM a;DIM b;{ ‚ ‚¢‚¤‚¦‚¨‚ ‚¢‚¤‚¦‚¨‚ ‚¢‚¤‚¦‚¨ } My Month " using ascii version functions in my code
len = lstrlen(lpSrc)+1; //Error Length is returned as 6 extra bytes
_fstrstr( lpStr, (LPSTR)szFind );
if( p ) {
pos = p - lpStr;
}
Using MBCS functions
len = _mbslen((unsigned char *)lpSrc)+1; // Length is correctly returned
ucP = _mbsstr((unsigned char *)lpStr, (unsigned char *)(LPSTR)szFind );if(ucP)
{
pos = ucP - (unsigned char *)lpStr; // Error here the difference is 6 extra bytes
}This problem happens only in japanese OS and that too in my application's editor. Removing the XP manifest file from my application folder seems to work fine. Doing a sample application of the same and testing in both english and japanese OS is working fine. Now I am changing my code to MBCS and then counting the double byte chars in my code and adjusting the position accordingly using below code.
int cPos = 0,count =0;
while(cPos<pos)
{
if( IsDBCSLeadByte(lpStr[cPos] ))
{
cPos = cPos + 2;
count++;
}
else
cPos++;
}
pos = pos - count;Thanks Satya
Today is a gift, that's why it is called the present.