version.h and unicode
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: version.h and unicode

  1. #1
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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.

  2. #2
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: version.h and unicode

    Take a look at Unicode topics.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  3. #3
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    Re: version.h and unicode

    Thanks ovidiucucu, I'll check it out.

    :-)

  4. #4
    Join Date
    May 2011
    Location
    India
    Posts
    18

    Smile 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 ?

  5. #5
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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.

  6. #6
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: version.h and unicode

    std::string has its Unicode version std::wstring.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  7. #7
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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.

  8. #8
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: version.h and unicode

    Quote Originally Posted by ManishaSantosh View Post
    [...] 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.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  9. #9
    ovidiucucu's Avatar
    ovidiucucu is offline Moderator/Reviewer Power Poster
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,021

    Re: version.h and unicode

    Quote Originally Posted by steveq View Post
    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.
    Ovidiu Cucu
    "When in Rome, do as Romans do."
    Visit: Microsoft Virtual Academy
    Follow: https://twitter.com/#!/ovidiucucu
    My blog: http://codexpert.ro/blog/author/ovidiu-cucu/

  10. #10
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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.

  11. #11
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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);

  12. #12
    Join Date
    Mar 2008
    Location
    Turin / Italy
    Posts
    178

    Re: version.h and unicode

    what is strsTemp? Is it a stringstream beacause std::string does not have a member functions called str().

  13. #13
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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);
    		}

  14. #14
    Join Date
    Mar 2008
    Location
    Turin / Italy
    Posts
    178

    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.

  15. #15
    Join Date
    Mar 2002
    Location
    Australia
    Posts
    170

    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

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center