Results 1 to 5 of 5

Thread: MinGW: char to WCHAR

  1. #1
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default MinGW: char to WCHAR

    Hi,

    I've been searching the net for the past 2 hours for a solution to the following problem, but I can't find anything. I'm trying to compile a project which requires WCHAR types (wrapper for Winamp DLLs). I tried including windows.h, wchar.h, tchar.h, stdlib.h, ... in my project, but I keep getting this error (I get multiple of these errors):
    winamp\winamp.cpp:581: error: cannot convert `char*' to `const WCHAR*' for argument `1' to `HINSTANCE__* LoadLibraryW(const WCHAR*)'
    Has anyone got any idea on how to fix this? I read some solutions for Visual Studio, but I'm using MinGw, so no help there.

    Best regards, Darhuuk

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: MinGW: char to WCHAR

    What's the content of winamp\winamp.cpp:581?
    J-P Nurmi

  3. #3
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MinGW: char to WCHAR

    Code I didn't write, it's basically a wrapper class for Winamp dlls, so you can have your program play any file type that Winamp can handle. This code works, no doubt about it, I tried other MP3 player code as well, which gave the same error.

    The problem is that the Win API functions need Unicode chars, which are 2 bytes wide, while chars are only 1 byte. I can fix some lines, by changing "string here", to L"string here"', which converts every chars to 2 bytes, but that won't work for lines with variables of course.

    This website describes the problem in more detail: http://www.codeproject.com/KB/string...ingguide1.aspx

    Is there any template or preprocessor code I could use that would convert chars to WCHARs or do some other magic? I can definately edit this one cpp file, but I'm afraid I'm going to run into this problem a lot more in the future and a general solution would certainly come in handy.

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    442
    Thanked 60 Times in 56 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MinGW: char to WCHAR

    -DUNICODE enables Unicode winapi Function calls. So removing this define should solve your problem. Otherwise you have no chance and replace all function calls with the correct unicode/ansi calls -> LoadLibrarayW/LoadLibraryA

  5. The following user says thank you to ChristianEhrlicher for this useful post:

    Darhuuk (25th March 2008)

  6. #5
    Join Date
    Jan 2008
    Posts
    32
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: MinGW: char to WCHAR

    Thanks, I'll try tomorrow and see if that fixes it. I had wanted to try, but I thought it was a flag Qt needed.

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 20:48
  2. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 20:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.