hyperionjv / bluecove

Automatically exported from code.google.com/p/bluecove
0 stars 0 forks source link

Exception message strings are empty for platforms based on localized windows #116

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
--------------------------------------
1. Env: BlueCove 2.1.0, winsock stack, ***Localized*** Windows XP 32bit SP3
2. Cause some BluetoothConnectionException, for example
3. Look at exception message string -- it's empty

What is the expected output? What do you see instead?
-----------------------------------------------------
* The message string should contain winsock detailed message string + error code

What BlueCove version are you using (include build number for SNAPSHOT)? 
------------------------------------------------------------------------
* v2.1.0

On what operating system and jvm? Is this 64-bit or 32-bit OS and jvm?
----------------------------------------------------------------------
***Localized*** Windows XP 32bit SP3 (localized mean that the interface 
language of Windows is in language other than English)

Please provide any additional information below.
------------------------------------------------
The problem is in file intelbth/common.cpp, line 262 (call to FormatMessage in 
getWinErrorMessage function).
Current implementation assumes neutral language. This cause windows to return 
some localized message stored in WCHAR string. If the message contains 
non-ascii characters, as happens on localized windows case, later translation 
to Java may fail. For example, line 228 (call to _vsnprintf_s in 
throwBluetoothConnectionException function) will fail and for this reason we 
get empty strings at the Java side.

As far as I know _vsnprintf_s does not support UTF-8 encoding, and therefore it 
might be hard to supply a general solution here.

I suggest the following workaround: when calling FormatMessage, always request 
the results in English. Technically, replace the 0 parameter in line 265 with 
"MAKELANGID(LANG_ENGLISH,SUBLANG_NEUTRAL)". This solved my problem; but maybe 
such change is required in other places in code.

Original issue reported on code.google.com by guf...@gmail.com on 18 Aug 2010 at 3:00