0

bellow error message when compiling snippets.cpp. this happen when there is a call to LoadFile. I am using simpleIni4.2

>     1>------ Build started: Project: SimpleIni, Configuration: Debug Unicode Win32 ------
>     1>Build started 2013-05-24 08:48:37.
>     1>ClCompile:
>     1>  snippets.cpp
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(48): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetAllKeys'
> : cannot convert parameter 1 from 'const char [13]' to 'const wchar_t
> *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(54): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetValue' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(61): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetValue' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(65): error C2664:
> 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::GetAllValues' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(84): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [12]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(91): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [12]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(97): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::SetValue' :
> cannot convert parameter 1 from 'const char [8]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(107): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Delete' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>c:\documents\simpleini-4.22\simpleini\snippets.cpp(110): error C2664: 'CSimpleIniTempl<SI_CHAR,SI_STRLESS,SI_CONVERTER>::Delete' :
> cannot convert parameter 1 from 'const char [13]' to 'const wchar_t *'
>     1>          with
>     1>          [
>     1>              SI_CHAR=wchar_t,
>     1>              SI_STRLESS=SI_GenericCase<wchar_t>,
>     1>              SI_CONVERTER=SI_ConvertW<wchar_t>
>     1>          ]
>     1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
>     1>
>     1>Build FAILED.
>     1>
> 
> 1>Time Elapsed 00:00:02.41
> ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Patashu
  • 21,443
  • 3
  • 45
  • 53
Bayo Alen
  • 341
  • 1
  • 6
  • 13

1 Answers1

0

Judging from the compiler's error message, it seems like you're passing a narrow string literal when the function is expecting a pointer to a wide string.

Try specifying L before the string literal, so that a pointer to a wide string literal (i.e. an object with type const wchar_t[]) will be passed to GetAllKeys()`:

GetAllKeys(L"Whatever\\Your\\Key\\Is");
//       ^

Also, notice that there are more instances of this error. Specifically, you should apply the above to all your calls for which the compiler is reporting an error, including calls to the following functions:

  • GetAllKeys()
  • GetValue()
  • SetValue()
  • Delete()

And all other possible situations that I could not deduce from the error message you posted.

Andy Prowl
  • 124,023
  • 23
  • 387
  • 451
  • I did LoadFile(L"Config.INI"); same problem still. – Bayo Alen May 24 '13 at 13:06
  • @BayoAlen: I don't think you are getting the same error message. What's the error message? – Andy Prowl May 24 '13 at 13:07
  • @BayoAlen: Also notice, that there are more instances of that error. The compiler is listing all the functions that accept a wide string, and for which you're providing a narrow string – Andy Prowl May 24 '13 at 13:10
  • actually LoadFile signature is LoadFile(constchar*) and I checked the error message there are the same – Bayo Alen May 24 '13 at 13:13
  • @BayoAlen: OK, in fact the compiler is not complaining about calls to `LoadFile()`. I was misled by the text of your question ("*this happen when there is a call to LoadFile*"). The compiler is complaining about calls to the functions I listed in my edited answer. Those are the functions to which you have to provide a wide string. – Andy Prowl May 24 '13 at 13:15
  • can you give and example? i don't get it – Bayo Alen May 24 '13 at 13:19
  • the AddEntry method for instance has const SI_CHAR* has parametter. her is the link of the simpleIni project sources http://code.google.com/p/simpleini/downloads/list – Bayo Alen May 24 '13 at 13:32
  • @BayoAlen: SO is not a help desk. You don't just toss code at people and ask for people to fix it. You should prepare an [SSCCE](http://sscce.org). And most importantly, you should read what the compiler is telling you. If you do that, and read my answer carefully, you would find that it solves your problem. – Andy Prowl May 24 '13 at 13:34
  • I am just talking about a code that everyone says it is portable and run both on windows and linux so far i was able to compile the same code on visual studio 2012 only, cannot be build with either gcc or visual studio 2010 – Bayo Alen May 24 '13 at 14:29