warning C4996: 'mbstowcs': This function or variable may be unsafe. Consider using mbstowcs_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

에러 발생시 변경방법

변경전 소스(Warning 발생)

wchar_t* CharToWChar(const char* pstrSrc)
{
    ASSERT(pstrSrc);
    int nLen = strlen(pstrSrc)+1;

    wchar_t* pwstr      = (LPWSTR) malloc ( sizeof( wchar_t )* nLen);
        
size_t ConvertedChars = 0;
    mbstowcs(pwstr, pstrSrc, nLen);
    return pwstr;    
}

변경후 소스

wchar_t* CharToWChar(const char* pstrSrc)
{
    ASSERT(pstrSrc);
    size_t nLen = strlen(pstrSrc)+1; // Warning 4996 방지..

    wchar_t* pwstr      = (LPWSTR) malloc ( sizeof( wchar_t )* nLen);
        
size_t ConvertedChars = 0;
mbstowcs_s(&ConvertedChars, pwstr, nLen, pstrSrc, _TRUNCATE); // Warning 4996 방지..
    return pwstr;    
}

+ Recent posts