-
June 6th, 2011, 08:15 AM
#1
version.h and unicode
Hey All,
I'm a bit of a newbie to implementing unicode into my software, I've used version.h before to grab the version number of my program, but this no longer compiles with my unicode MFC app.
Has anyone converted version.h to unicode, or does anyone know what I have to do to easily fix this please?
Perhaps there is another way to grab my current version number?
Here are the compiler errors:
Code:
1>version.h(37) : error C2440: 'initializing' : cannot convert from 'const char [1]' to 'TCHAR [260]'
1> There is no context in which this conversion is possible
1>version.h(41) : error C2440: 'initializing' : cannot convert from 'TCHAR [260]' to 'std::basic_string<_Elem,_Traits,_Ax>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>version.h(47) : error C2664: 'GetFileVersionInfoSizeW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>version.h(56) : error C2664: 'GetFileVersionInfoW' : cannot convert parameter 1 from 'char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>version.h(64) : error C2664: 'VerQueryValueW' : cannot convert parameter 2 from 'const char [25]' to 'LPWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>version.h(119) : error C2440: 'const_cast' : cannot convert from 'const char *' to 'LPTSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>version.h(122) : error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it)' : cannot convert parameter 1 from 'LPTSTR' to 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
1> Constructor for struct 'std::basic_string<_Elem,_Traits,_Ax>::_Has_debug_it' is declared 'explicit'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _Ax=std::allocator<char>
1> ]
Thanks heaps for your help.
Steve Q.
-
June 7th, 2011, 05:03 AM
#2
Re: version.h and unicode
Take a look at Unicode topics.
-
June 7th, 2011, 07:17 AM
#3
Re: version.h and unicode
Thanks ovidiucucu, I'll check it out.
:-)
-
June 7th, 2011, 08:22 AM
#4
Re: version.h and unicode
Unicode is bit boaring for the programming purpose. U need to convert all string variables into unicode format e.g char buf[80] -> TCHAR buf[80]. U need to use unicode specific functions that u will find on net. e.g fopen -> _tfopen etc.
u will need to load strings from string table to serve the purpose of using unicode.
what is ur purpose of using unicode ?
-
June 7th, 2011, 08:39 AM
#5
Re: version.h and unicode
I'm writing a subcaptioning system for DCI compliant digital cinema projectors (the ones that play the 3D movies). I used version.h to interrogate the version string information in my source code, but I can't get it to compile because of unicode.
I need unicode to support languages worldwide.
Version.h uses std::string, and I don't know how to use this with unicode.
Thanks
Steve Q.
-
June 7th, 2011, 09:01 AM
#6
Re: version.h and unicode
std::string has its Unicode version std::wstring.
-
June 7th, 2011, 09:06 AM
#7
Re: version.h and unicode
thanks ovidiucucu, I found this about 30secs before your post came in!
I have almost fixed it now, but have 2 errors to go.
This cast is causing me issues:
Code:
const_cast<LPTSTR>(strsTemp.str().c_str()),
compiler error:
Code:
error C2440: 'const_cast' : cannot convert from 'const char *' to 'LPTSTR' version.h 120
Thanks again all,
Steve Q.
-
June 7th, 2011, 09:06 AM
#8
Re: version.h and unicode
Originally Posted by ManishaSantosh
[...] U need to convert all string variables into unicode format e.g char buf[80] -> TCHAR buf[80]. U need to use unicode specific functions that u will find on net. e.g fopen -> _tfopen etc.
Neither TCHAR buf[80] is a "string vartiable in unicode format", nor _tfopen is "unicode specific function".
Both ar just macros, defined in TCHAR.H.
-
June 7th, 2011, 09:15 AM
#9
Re: version.h and unicode
Originally Posted by steveq
This cast is causing me issues:
Code:
const_cast<LPTSTR>(strsTemp.str().c_str()),
compiler error:
Code:
error C2440: 'const_cast' : cannot convert from 'const char *' to 'LPTSTR' version.h 120
Never cast ANSI strings to Unicode and vice-versa.
If necessary use conversion functions or macros.
See this thread: http://www.codeguru.com/forum/showth...light=wcstombs
Last edited by ovidiucucu; June 7th, 2011 at 09:17 AM.
-
June 7th, 2011, 09:31 AM
#10
Re: version.h and unicode
Ok so do you mean I have to convert:
Code:
strsTemp.str().c_str()
Before it is passed to the function...
To be honest I'm still not sure how to fix this. I get the same error with this:
Code:
return static_cast<LPTSTR>(pvValue);
Compiler error:
Code:
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const _Elem *)' : cannot convert parameter 1 from 'LPTSTR' to 'const char *' version.h 123
Thanks again.
-
June 7th, 2011, 09:41 AM
#11
Re: version.h and unicode
Sorry I should have posted the offending code, here it is:
Code:
if(::VerQueryValue(static_cast<LPVOID>(m_pucResourceData),
const_cast<LPTSTR>(strsTemp.str().c_str()),
static_cast<LPVOID *>(&pvValue),
&uiSize) != FALSE)
return static_cast<LPTSTR>(pvValue);
-
June 7th, 2011, 09:55 AM
#12
Re: version.h and unicode
what is strsTemp? Is it a stringstream beacause std::string does not have a member functions called str().
-
June 7th, 2011, 09:59 AM
#13
Re: version.h and unicode
Yeah it is:
Code:
if(m_pucResourceData)
{
UINT uiSize = 0;
std::stringstream strsTemp;
LPVOID pvValue = 0;
// Build query string
strsTemp << "\\StringFileInfo\\" << std::setw(4) << std::setfill('0') << std::hex
<< m_pLanguageInformation->m_wLanguage << std::setw(4) << std::hex
<< m_pLanguageInformation->m_wCodePage << "\\" << refcstrKey;
if(::VerQueryValue(static_cast<LPVOID>(m_pucResourceData),
const_cast<LPTSTR>(strsTemp.str().c_str()),
static_cast<LPVOID *>(&pvValue),
&uiSize) != FALSE)
return static_cast<LPTSTR>(pvValue);
}
-
June 7th, 2011, 10:01 AM
#14
Re: version.h and unicode
use std::wstringstream and u're OK.
http://msdn.microsoft.com/en-us/libr...=vs.71%29.aspx
Also use the wide version of string literals
Code:
L"\\StringFileInfo\\"
or
Code:
_T("\\StringFileInfo\\")
Last edited by SkyNetTo; June 7th, 2011 at 10:05 AM.
-
June 7th, 2011, 10:05 AM
#15
Re: version.h and unicode
Thanks SkyNetTo.
I tried that, but got more errors:
Code:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Fillobj<_Elem>' (or there is no acceptable conversion) version.h 115
error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const _Elem *)' : cannot convert parameter 1 from 'LPTSTR' to 'const char *' version.h 123
??
Thanks heaps for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|