Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. My first Win32 program...

My first Win32 program...

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
11 Posts 7 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xelios
    wrote on last edited by
    #1

    Following is the code of my program...

    #include "stdafx.h"
    #include "windows.h"

    int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
    }

    While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

    Mohsin Ali

    C S H T 6 Replies Last reply
    0
    • X xelios

      Following is the code of my program...

      #include "stdafx.h"
      #include "windows.h"

      int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
      {
      MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
      }

      While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

      Mohsin Ali

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      It is because UNICODE is defined. If you want a full understanding, a strongly suggest this article[^].

      Cédric Moonen Software developer
      Charting control [v1.4]

      1 Reply Last reply
      0
      • X xelios

        Following is the code of my program...

        #include "stdafx.h"
        #include "windows.h"

        int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
        {
        MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
        }

        While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

        Mohsin Ali

        S Offline
        S Offline
        sudhir_Kumar
        wrote on last edited by
        #3

        It happens because the project is built for UNICODE.

        Sudhir Kumar

        X Z 2 Replies Last reply
        0
        • X xelios

          Following is the code of my program...

          #include "stdafx.h"
          #include "windows.h"

          int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
          {
          MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
          }

          While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

          Mohsin Ali

          S Offline
          S Offline
          sudhir_Kumar
          wrote on last edited by
          #4

          In build toolbar select Win32 Release or Win32 debug.

          Sudhir Kumar

          1 Reply Last reply
          0
          • S sudhir_Kumar

            It happens because the project is built for UNICODE.

            Sudhir Kumar

            X Offline
            X Offline
            xelios
            wrote on last edited by
            #5

            Then how can I change... I mean what I have to do in order to remove this error..

            Mohsin Ali

            C 1 Reply Last reply
            0
            • X xelios

              Following is the code of my program...

              #include "stdafx.h"
              #include "windows.h"

              int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
              {
              MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
              }

              While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

              Mohsin Ali

              H Offline
              H Offline
              Hamid Taebi
              wrote on last edited by
              #6

              Use of this MessageBox(NULL, _T("This is my first windows program\n Author: Mohsin"), _T("Virtual University"), ...

              1 Reply Last reply
              0
              • X xelios

                Then how can I change... I mean what I have to do in order to remove this error..

                Mohsin Ali

                C Offline
                C Offline
                Cedric Moonen
                wrote on last edited by
                #7

                Use generic text mappings instead of using char arrays. This way if you want to enable UNICODE later on, your program will support it.

                Cédric Moonen Software developer
                Charting control [v1.4]

                1 Reply Last reply
                0
                • X xelios

                  Following is the code of my program...

                  #include "stdafx.h"
                  #include "windows.h"

                  int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
                  {
                  MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
                  }

                  While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

                  Mohsin Ali

                  S Offline
                  S Offline
                  sudhir_Kumar
                  wrote on last edited by
                  #8

                  Did you got any success with these replyes.

                  Sudhir Kumar

                  1 Reply Last reply
                  0
                  • X xelios

                    Following is the code of my program...

                    #include "stdafx.h"
                    #include "windows.h"

                    int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
                    {
                    MessageBox(NULL, "This is my first windows program\n Author: Mohsin", "Virtual University", MB_OK|MB_ICONINFORMATION);
                    }

                    While building it is throwing following error.. Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [49]' to 'LPCWSTR' e:\visual programming\practices\test\test\p_66.cpp 6 test

                    Mohsin Ali

                    T Offline
                    T Offline
                    toxcct
                    wrote on last edited by
                    #9

                    change you code into the following. and in a general mean, always use _T() around you literal strings to avoid to matter whether Unicode is defined or not :

                    #include "stdafx.h"
                    #include "windows.h"

                    int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
                    MessageBox(
                    NULL,
                    **_T(**"This is my first windows program\n Author: Mohsin"**)**,
                    **_T(**"Virtual University"**)**,
                    MB_OK|MB_ICONINFORMATION);
                    }

                    [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                    1 Reply Last reply
                    0
                    • S sudhir_Kumar

                      It happens because the project is built for UNICODE.

                      Sudhir Kumar

                      Z Offline
                      Z Offline
                      zafersavas
                      wrote on last edited by
                      #10

                      Sorry but I will complain about the answering style of some people. For example in this question it is obvious that he is a newbie and facing a simple problem. But look at the answers to that simple question. Its because you are in UNICODE...... is this the answer? Think about the person expecting a solution : so what? What am I supposed to do? Where should I read? Would not it be better if you answer it in such a way. (like the way toxcct did for example) It's because of ......, You should try a code like ......, For more info you can read .... web page At the top of the forum there is a default subject "How to get an answer to your question" and I think there should be another one "HOW TO ANSWER A QUESTION".

                      D 1 Reply Last reply
                      0
                      • Z zafersavas

                        Sorry but I will complain about the answering style of some people. For example in this question it is obvious that he is a newbie and facing a simple problem. But look at the answers to that simple question. Its because you are in UNICODE...... is this the answer? Think about the person expecting a solution : so what? What am I supposed to do? Where should I read? Would not it be better if you answer it in such a way. (like the way toxcct did for example) It's because of ......, You should try a code like ......, For more info you can read .... web page At the top of the forum there is a default subject "How to get an answer to your question" and I think there should be another one "HOW TO ANSWER A QUESTION".

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        zafersavas wrote:

                        Its because you are in UNICODE...... is this the answer? Think about the person expecting a solution : so what? What am I supposed to do? Where should I read?

                        That would be a good enough clue for most. At this point, the OP simply needs to do this.

                        "Love people and use things, not love things and use people." - Unknown

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups