Thread: MessageBoxW Error (type casting) param 2 from char[29] to LPCWSTR

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    MessageBoxW Error (type casting) param 2 from char[29] to LPCWSTR

    Error on this line, and multiple others:

    Code:
    			MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
    Now, did this work in the past? I don't remember changing it in any previous projects and I'm wondering why this won't work, I know I can make a way to work around it I'm just asking!


    Code:
    error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [29]' to 'LPCWSTR'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Also to note, I'm including these headers into the source file this is in, not sure if it affects the situation though:

    Code:
    // Main.cpp : Defines the entry point for the console application.
    //
    #include "stdafx.h"
    #include <time.h>
    #include "Blackjack_Game.h"
    #include "State_Manager.h"
    #include "Play_State.h"
    #include <windows.h>		// Header File For Windows
    #include <gl\gl.h>			// Header File For The OpenGL32 Library
    #include <gl\glu.h>			// Header File For The GLu32 Library
    #include <gl\glaux.h>		// Header File For The Glaux Library
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Go in project options. Under general, set character set to multi-byte character set.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Thanks, that solved the issue right away!
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Tada!
    Remember that LPCWSTR = Unicode and LPCSTR = ANSI.
    You can also look at MessageBoxW. That is another dead giveaway that it's unicode and not ANSI (multi-byte).
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. The Interactive Animation - my first released C program
    By ulillillia in forum A Brief History of Cprogramming.com
    Replies: 48
    Last Post: 05-10-2007, 02:25 AM
  2. NAQ: Everything you never wanted to know about CPP
    By evildave in forum C Programming
    Replies: 21
    Last Post: 12-12-2005, 10:56 AM