2007년 02월 21일
wchar -> char 와 char -> wchar
프로젝트 마무리할때 나는 비쥬얼 C++ 6.0에서 작업을했다.(디바이스드라이버 개발때문에)
그리고 같은 조원들은 닷넷 2005에서 작업을하였다.
나중에 내가 만든 모듈을 합치는데 닷넷 2005에서는 기본적으로 wchar_t를 사용하여
형변환을 하는데 난감하였다. (LPSTR)(LPCSTR). .GetBuffer()등이 모두 먹히지않았다.
인터넷 검색도중 찾은소스. 나중에 유용할꺼같아서 스크랩트~
/////////////////////////////////////////////////////////////////////
// char -> wchar
wchar_t* CharToWChar(const char* pstrSrc)
{
ASSERT(pstrSrc);
int nLen = strlen(pstrSrc)+1;
wchar_t* pwstr = (LPWSTR) malloc ( sizeof( wchar_t )* nLen);
mbstowcs(pwstr, pstrSrc, nLen);
return pwstr;
}
/////////////////////////////////////////////////////////////////////
// wchar -> char
char* WCharToChar(const wchar_t* pwstrSrc)
{
ASSERT(pwstrSrc);
#if !defined _DEBUG
int len = 0;
len = (wcslen(pwstrSrc) + 1)*2;
char* pstr = (char*) malloc ( sizeof( char) * len);
WideCharToMultiByte( 949, 0, pwstrSrc, -1, pstr, len, NULL, NULL);
#else
int nLen = wcslen(pwstrSrc);
char* pstr = (char*) malloc ( sizeof( char) * nLen + 1);
wcstombs(pstr, pwstrSrc, nLen+1);
#endif
return pstr;
}
이 글과 관련있는 글을 자동검색한 결과입니다 [?]
- [012]Buffer Manipulation, size_t 그리고 memset by sally
- [기초] 복사생성자, 복사연산자 by 우하하
- 문자열 형식간 변환 3. _bstr_t 에서 변환 예제 by 셀린™
- [015]memcpy의 사용법을 알아보자 by sally
- Secure Handling Argument In C by Mr8Blog
# by | 2007/02/21 19:49 | MFC | 트랙백(5) | 덧글(1)





☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
제목 : Compare darvocet and percocet.
Percocet verses lortabs. Identify percocet 93-490. Percocet. Identify a percocet 93-490. Buy percocet online without office visit....more
제목 : Buy ambien online order chea..
Cheap ambien online order ambien now with discount. Ambien cheap. Cheap ambien. Online ambien cheap....more
제목 : Affordable payday loans otta..
Unsecured payday loans no fax fast approval. Payday loans. Online payday loans gauranteed. Mexico country payday loans. Georgia payday loans. No fax payday loans. Help for people in trouble with payday loans. Payday loans payments news archive....more
제목 : Athens to paris cheap flights.
Cheap flights paris. Cheap flights to paris from phl. Athens to paris cheap flights....more
제목 : Online auto insurance quotes.
California auto insurance quote online. Rhode island online auto insurance quotes. Auto insurance online. Online auto insurance....more
감사드립니다.
좋은 하루 되세요~~