CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2006
    Posts
    5

    Angry Problems with first Win32... pls help!

    Hello everyone!

    I'm a newbie to windows programming, having migrated from Linux, and am having problems even with my Hello World app... Could someoen please tell me what I am doing wrong here... thanks!


    #include <windows.h>

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
    LPSTR lpCmdLine, int nShowCmd )
    {
    MessageBox( NULL, "I finally work!",
    "Hello World", MB_OK | MB_ICONEXCLAMATION ) ;
    }

    The error says Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [16]' to 'LPCWSTR'

    Thanks in advance!

  2. #2
    Join Date
    May 2005
    Posts
    4,954

    Re: Problems with first Win32... pls help!

    Looks like you are using Unicode build in that case change the code:

    Code:
    ::MessageBox( NULL, _T("I finally work!"),_T("Hello World"), MB_OK | MB_ICONEXCLAMATION ) ;
    
    // or
    
    ::MessageBox( NULL, L"I finally work!",L"Hello World", MB_OK | MB_ICONEXCLAMATION ) ;
    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  3. #3
    Join Date
    Feb 2006
    Posts
    5

    Red face Re: Problems with first Win32... pls help!

    Hmm... unicode build eh? Is that the standard? Is there another mode I should use? I use VS2005. Thanks for the info!

  4. #4
    Join Date
    Feb 2006
    Posts
    5

    Angry Re: Problems with first Win32... pls help!

    My compiler cannot find the _T...

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Problems with first Win32... pls help!

    Quote Originally Posted by jwcalifo
    My compiler cannot find the _T...
    Help the compiler to find it.
    include <TCHAR.H>
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

  6. #6
    Join Date
    Oct 2005
    Posts
    230

    Re: Problems with first Win32... pls help!

    If you are just beginning with WIN32 applications i would not worry about doing anything with unicode, its just tht bit of exta work that makes things more complex..

  7. #7
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Problems with first Win32... pls help!

    Quote Originally Posted by UnfitElf
    If you are just beginning with WIN32 applications i would not worry about doing anything with unicode, its just tht bit of exta work that makes things more complex..
    Yeah, sure, but making a habit from Using Generic-Text Mappings (also definitions for generic international functions from TCHAR.H) even for a beginner is not bad.
    Later, maybe he/she will work on a serious comercial application and if he/she will consider that "its just tht bit of exta work that makes things more complex" usually will ignore that.
    One day, when the application is complex with tens/hundred of thousands lines of code, the boss comes and says "We have to deploy on Japanese market, ASAP!!!".
    Then he/she will see indeed much much (usually unallocated in the development plan) extra work necessary.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured