MFC public methods

Source: Internet
Author: User

1. Character conversions

1) conversion between a narrow character and a wide character

Wstring convertstringtowstring (const std::string & str)
{
int nlen = (int) str.size ();

int nSize = MultiByteToWideChar (CP_ACP, 0, (LPCSTR) str.c_str (), Nlen, 0, 0);

if (nSize <= 0)
{
return L "";
}

WCHAR *PWSZDST = new Wchar[nsize+1];

if (NULL = = PWSZDST)
{
return L "";
}

MultiByteToWideChar (CP_ACP, 0, (LPCSTR) str.c_str (), Nlen, PWSZDST, nSize);

Pwszdst[nsize] = 0;

Wstring wcharstring;

if (pwszdst[0] = = 0xFEFF)//Skip Oxfeff
{
for (int i = 0; i < nSize; i + +)
Pwszdst[i] = pwszdst[i+1];

Wstring wcharString1 (pwszdst,nsize-1);

wcharstring = wcharString1;
}
Else
{
Wstring wcharString2 (pwszdst,nsize);

wcharstring = wcharString2;
}

Delete pwszdst;

return wcharstring;
}

void Conerttchartostring (TCHAR * ori,string * str)
{
int wlen = (int) (Wcslen (ori) + 1);

int Alen=widechartomultibyte (cp_acp,0,ori,wlen,null,0, null,null);

char * LPA = new char [ALen];

WideCharToMultiByte (Cp_acp,0,ori,wlen,lpa, alen,null,null);

*str = LPA;

delete [] LPA;
}

MFC public methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.