본문 바로가기
  • fishing...
  • eating...
MISCELLANEOUSNESS

cannot convert from 'char [ ]' to 'LPWSTR' 에러 해결 방법

by 회색뿔 2008. 1. 10.


cannot convert parameter 1 from 'char [40]' to 'LPWSTR' 에러 발생시 해결 방법

아래처럼 해결 하면 된다.. 쿄쿄

VS.Net 2005에서 사용해본 결과 기본적으로 'LPWSTR' 타입을 사용하고 있었으므로..


wchar_t * pExeFile = ...;

wchar_t * pModuleFile = ...;

 

swprintf(pExeFile, L"%s", pModuleFile);


이처럼 하는게 좋을 거 같다..

swprintf(pExeFile, L"%s", pModuleFile);

위 부분에서 L을 빼먹으면 또 에러가 나니 조심...

char * pExeFile = ...;

char * pModuleFile = ...;

 

sprintf(pExeFile, "%s", pModuleFile);

 

or

 

wchar_t * pExeFile = ...;

wchar_t * pModuleFile = ...;

 

swprintf(pExeFile, L"%s", pModuleFile);

 

or

 

#include <TCHAR.h>

. . .

LPCTSTR pExeFile = ...;

LPCTSTR pModuleFile = ...;

 

_stprintf(pExeFile, _T("%s"), pModuleFile);

 

or a mixture:

 

wchar_t * pExeFile = ...;

char * pModuleFile = ...;

 

swprintf(pExeFile, L"%hs", pModuleFile);

 

or

 

char * pExeFile = ...;

wchar_t * pModuleFile = ...;

 

sprintf(pExeFile, "%ws", pModuleFile);



//  char -> wchar
/////////////////////////////////////////////////////////////////////
void CharToWChar( wchar_t* pwstrDest, const char* pstrSrc )
{
    int nLen = (int)strlen(pstrSrc)+1;
    mbstowcs( pwstrDest, pstrSrc, nLen);
}

// wchar -> char
/////////////////////////////////////////////////////////////////////
void WCharToChar( char* pstrDest, const wchar_t* pwstrSrc )
{
    int nLen = (int)wcslen(pwstrSrc);
    wcstombs(pstrDest, pwstrSrc, nLen+1);
}