widechar functions in cygwin

This is a discussion on widechar functions in cygwin within the Windows Programming forums, part of the Platform Specific Boards category; Im trying to compile a win32 program in unicode with cygwin but I keep getting the error: Code: void MsgBox(const ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    330

    widechar functions in cygwin

    Im trying to compile a win32 program in unicode with cygwin but I keep getting the error:

    Code:
    void MsgBox(const wchar_t *message, const wchar_t *title, int flags)
    {
      MessageBox(m_hwnd, message, title, flags);
    }
    window.cpp: In function 'void MsgBox(const wchar_t*, const wchar
    _t*, int)':
    window.cpp:52: error: cannot convert 'const wchar_t*' to 'const CHAR*' for a
    rgument '2' to 'int MessageBoxA(HWND__*, const CHAR*, const CHAR*, UINT)'

    apparently it's trying to compile the char versions, but I did specify

    CFLAGS="-DUNICODE -D_UNICODE"
    CXXFLAGS="-DUNICODE -D_UNICODE"

    in the makefile.

    What else do I need to do to get the widechar versions?

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    Try a big fat #define UNICODE and #define _UNICODE at the top of your code

  3. #3
    Registered User
    Join Date
    Jan 2007
    Posts
    330
    did that before every windows.h include but still same problem. compiles fine in visual studio but not cygwin

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Cygwin Unicode support came out the end of last year, not sure if that would make a difference.

    Or if you can...
    Code:
    void MsgBox(const TCHAR * message, const TCHAR * title, int flags)
    {
      MessageBox(m_hwnd, message, title, flags);
    }
    Or:
    Code:
    void MsgBox(LPCTSTR message, LPCTSTR title, int flags)
    {
      MessageBox(m_hwnd, message, title, flags);
    }
    That way who cares whether Unicode is set (although it might matter upstream).

    Otherwise, if you don't care about the ANSI version, use MessageBoxW() instead...
    Last edited by zacs7; 08-10-2010 at 05:09 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array of functions
    By frktons in forum C Programming
    Replies: 29
    Last Post: 06-30-2010, 09:51 AM
  2. Need help with functions
    By jusfry01 in forum C Programming
    Replies: 2
    Last Post: 05-22-2010, 06:25 PM
  3. Void Functions Help
    By bethanne41 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2005, 05:30 PM
  4. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 11:50 AM
  5. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 02:35 AM

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