PDA

View Full Version : MinGW: char to WCHAR



Darhuuk
23rd March 2008, 15:19
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

jpn
23rd March 2008, 17:33
What's the content of winamp\winamp.cpp:581?

Darhuuk
23rd March 2008, 22:17
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/cppstringguide1.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.

ChristianEhrlicher
25th March 2008, 12:29
-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

Darhuuk
25th March 2008, 23:21
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.