win32 can not compile simple program

This is a discussion on win32 can not compile simple program within the Windows Programming forums, part of the Platform Specific Boards category; Hello, I have the following code: Code: #include <windows.h> int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { ...

  1. #1
    zee
    zee is offline
    Registered User
    Join Date
    Jun 2004
    Posts
    34

    win32 can not compile simple program

    Hello, I have the following code:

    Code:
    #include <windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow)
    {
        MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
        return 0;
    }
    However It gives me the following problems when i compile:

    Code:
    ------ Build started: Project: RTS, Configuration: Debug Win32 ------
    Compiling...
    simple.cpp
    c:\simple.cpp(6) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    Build log was saved at "file://c:\BuildLog.htm"
    RTS - 1 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
    Please help. I am running windowsxp sp2 and compiling with fresh compy ofvisual studio c++ express with the platform sdk

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Somehow, you have UNICODE defined for your project. This means that MessageBox() will take wide character strings. You can compile your code by changing it to:

    Code:
    #include <windows.h>
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
        LPSTR lpCmdLine, int nCmdShow)
    {
        MessageBox(NULL,TEXT( "Goodbye, cruel world!"),TEXT( "Note"), MB_OK);
        return 0;
    }
    Or you can undefine UNICODE, and your code will compile as it is.

  3. #3
    zee
    zee is offline
    Registered User
    Join Date
    Jun 2004
    Posts
    34
    Thanx!

    where can i disable this unicode crap?

  4. #4
    zee
    zee is offline
    Registered User
    Join Date
    Jun 2004
    Posts
    34
    Also can you explain how u found the solution there?

    i did not figure that out,

    thank you very much

  5. #5
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Quote Originally Posted by zee
    Also can you explain how u found the solution there?

    i did not figure that out,

    thank you very much
    From your error message about MessageBoxW
    MessageBoxW is the unicode version of MessageBox which is really just a macro. If unicode is defined, the macro returns MessageBoxW, if not it returns MessageBoxA.

    As far as turning it off, look in your projects properties for a setting called "Character set", there are three options, "not set", "use unicode...", "use multibyte ...". To switch to ascii set it to "not set"

    This is for VS2005/and c++ express edition and I believe VS2003 as well.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    "Disable this UNICODE crap"

    Microsoft pushes towards using Unicode. The world pushes towards using Unicode. It's a good idea to make your apps work with it, instead of fighting it.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    zee
    zee is offline
    Registered User
    Join Date
    Jun 2004
    Posts
    34
    thank you darryl

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Microsoft pushes towards using Unicode. The world pushes towards using Unicode. It's a good idea to make your apps work with it, instead of fighting it.
    Absolutely agree.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    I strongly suggest supporting Unicode as well.

    Start coding with it SOON! Like..NOW! It isn't too hard, either.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  10. #10
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    Quote Originally Posted by adrianxw
    Absolutely agree.
    i disagree, microsoft is a memory .......... the only reason i uise it is cus of DX but Microsoft pushes everything, and its not our boss geez.
    New Function!!!!

    glAddIdol(C+noob);

    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

  11. #11
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    i disagree, microsoft is a memory
    You apparently have no clue what UNICODE is, or what defining it does. Your hatred of Microsoft does not count as a good reason to discard unicode programming. If you have a real reason you would like to contribute, then by all means do so. Otherwise, please resist the urge to press the "Post Reply" button.

  12. #12
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Since Microsoft's developers aren't the only ones supporting Unicode, I also don't see a link between Microsoft and Unicode...none at all.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    The link is that Microsoft is pushing for it hard.
    Oh, and Microsoft is on the Unicode consortium.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #14
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Ahh, I see.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  15. #15
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Oh, and Microsoft is on the Unicode consortium.
    So are Microsoft's competitors.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  2. Replies: 1
    Last Post: 12-30-2007, 10:08 AM
  3. Builder C++ large files support for simple C program
    By Murfury in forum C Programming
    Replies: 3
    Last Post: 11-23-2007, 03:47 PM
  4. newbie: steps to create and compile c program in SUSE
    By gemini_shooter in forum Linux Programming
    Replies: 12
    Last Post: 06-22-2005, 07:35 PM
  5. simple frontend program problem
    By gandalf_bar in forum Linux Programming
    Replies: 16
    Last Post: 04-22-2004, 07:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21