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;
}

by 프레야 | 2007/02/21 19:49 | MFC | 트랙백(5) | 덧글(1)

트랙백 주소 : http://beehone.egloos.com/tb/946502
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Tracked from Effects of l.. at 2008/11/22 00:14

제목 : Compare darvocet and percocet.
Percocet verses lortabs. Identify percocet 93-490. Percocet. Identify a percocet 93-490. Buy percocet online without office visit....more

Tracked from Cheap ambien. at 2008/11/22 15:46

제목 : Buy ambien online order chea..
Cheap ambien online order ambien now with discount. Ambien cheap. Cheap ambien. Online ambien cheap....more

Tracked from Easy payday .. at 2008/11/23 08:20

제목 : 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

Tracked from Cheap flight.. at 2008/11/24 12:05

제목 : Athens to paris cheap flights.
Cheap flights paris. Cheap flights to paris from phl. Athens to paris cheap flights....more

Tracked from Online auto .. at 2008/11/24 21:29

제목 : Online auto insurance quotes.
California auto insurance quote online. Rhode island online auto insurance quotes. Auto insurance online. Online auto insurance....more

Commented by dinga at 2009/06/19 10:47
문자열 관련 작업을 하다가 도움을 받았습니다.
감사드립니다.
좋은 하루 되세요~~

:         :

:

비공개 덧글

◀ 이전 페이지다음 페이지 ▶