Character Encoding/Compiler differences + ofxGamepad

Hey all,

I’ve got a question that I’m wondering if anyone knows anything about.

I’m recoding one of my games into OpenFrameworks. I’m using Windows 7 and of v0.7.4 on both Code::Blocks and MSVC++ 2010 Express. (I also have VS11 installed, but I installed VC10 SP1 to fix the compile problems with VC10 for the time being. Also using the latest DX SDK.)

The problem I’ve run into is with the ofxGamepad addon. On Windows, the addon needs to grab the of app window’s HWND to init its InputManager class properly.

The master branch of the addon is actually completely broken on Windows, but I got it to work with the VC++ compiler with some changes (but the box2d addon’s triangle library breaks with that compiler, hence other problems).

I almost got it to work with the MinGW compiler, but with that one, the same code that properly grabbed the HWND in VC++ doesn’t work.

The relevant code is:

  
  
		if(hWnd == 0)  
		{  
//			HWND windowHandle = FindWindow(NULL, L"testApp");  
//			HWND windowHandle = FindWindowW(NULL, L"testApp");  
			HWND windowHandle = FindWindow(NULL, _T("testApp"));  
			std::ostringstream wnd;  
			wnd << (size_t)windowHandle;  
  
			pl.insert(std::make_pair( std::string("WINDOW"), wnd.str() ));  
//			pl.insert(std::make_pair( std::basic_string<TCHAR>("WINDOW"), wnd.str() ));  
		}  
  

The first FindWindow() works in VC++, but throws a “can’t convert ‘const wchar_t*’ to ‘LPCSTR’” error when using MinGW. Removing the L fixes the error in MinGW, but creates the opposite error in VC++. (Which isn’t necessarily a problem, since I already have two versions of the code for each compiler.)

I tried fixing this by using tchar.h (as you see with the line I’m actually using now). This compiles fine in both VC++ and MinGW and gives me a valid HWND in VC++ but an invalid one in MinGW.

So VC++ is kind of working, but ofxBox2D’s triangle library breaks the debugger (but not when using MinGW). It seems like this has something to do with how MinGW/gcc handles unicode/ansi? I’m at the limit at what I’ve been able to glean from documentation.

(Also, if anyone knows how to get the triangle library included in ofxBox2d to work with VC++, I’d also like to know. The solutions I’ve tried haven’t worked.)

Anyone have any ideas? Thanks!