This documentation is archived and is not being maintained.

Compiler Warning (level 1) C4906

string literal cast to 'LPWSTR'

The compiler detected an unsafe cast. The cast did succeed, but you should use a conversion routine.

This warning is off by default. See Compiler Warnings That Are Off by Default for more information.

The following sample generates C4906:

// C4906.cpp
// compile with: /W1
#pragma warning(default : 4906)
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
   LPWSTR x = (LPWSTR)"1234";   // C4906
   // try the following lines instead
   // char y[128];
   // wcstombs(&y[0], L"12345", 4);
   // printf("%s\n", y);
}
Show: