0

I'm creating a file in the following manner:

if ((BmpFile = CreateFile((LPCWSTR)"Test.bmp",
                          GENERIC_WRITE,
                          0, NULL,
                          CREATE_ALWAYS,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL)) == INVALID_HANDLE_VALUE)

But the file that gets created has name 敔瑳戮灭.

Clearly not what I'm looking for! I'm in the process of trying to learn the windows API, could anyone tell me what I have to change to make it output what I think it should? I've looked at http://msdn.microsoft.com/en-us/library/windows/desktop/aa363858%28v=vs.85%29.aspx and it hasn't helped me too much-- I think because I don't know what I'm looking for.

Premature edit: everything else works as expected in the function.

druckermanly
  • 2,694
  • 15
  • 27

1 Answers1

6

You don't create a WSTR by simply casting. If you want your fixed text to be a wide string, apply the L in front of the literal:

... = CreateFile( L"Test.bmp", ...
nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Oh, I thought it was as easy as casting! That's why it's not documented, it's common knowledge! What if I have a char*? – druckermanly May 20 '14 at 07:28
  • You do like we all do: you google it. One of the top ten links will lead you right [here](http://stackoverflow.com/questions/19715144/how-to-convert-char-to-lpcwstr) :) – nvoigt May 20 '14 at 07:32
  • I found that one, and am trying to use: wchar_t *convertCharArrayToLPCWSTR(const char* charArray) found at http://stackoverflow.com/questions/19715144/how-to-convert-char-to-lpcwstr/19717944#19717944 but it isn't working-- I'm getting the same text! EDIT: cleaned build , rebuilt, and it worked. Weird! – druckermanly May 20 '14 at 07:36