Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. error C2664 in MFC..?

error C2664 in MFC..?

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
25 Posts 4 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Software_Specialist

    ifstream message_file; TCHAR message[1000]; int i; message_file.get(message[i++]); ERROR C2664 : cannot convert parameter 1 from 'TCHAR' to 'char&' Any suggestions for the above problem

    CPalliniC Offline
    CPalliniC Offline
    CPallini
    wrote on last edited by
    #3

    Why are you mixing Generic-Text Mappings with a class specialized for elements of type char?

    Software_Specialist wrote:

    TCHAR message[1000];

    Try to change the above with:

    char message[1000];

    :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

    In testa che avete, signor di Ceprano?

    S 1 Reply Last reply
    0
    • CPalliniC CPallini

      Why are you mixing Generic-Text Mappings with a class specialized for elements of type char?

      Software_Specialist wrote:

      TCHAR message[1000];

      Try to change the above with:

      char message[1000];

      :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      S Offline
      S Offline
      Software_Specialist
      wrote on last edited by
      #4

      well i am well confused now. okay pls have a look over this post of mine where i discussed mainly about char variable... http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2073148&df=100&fr=26 Now all of them said me to use TCHAR in place of char or wchar_t.. I have not defined UNICODE...All of them said that TCHAR can handle both UNICODE nad non UNICODE ...So its always better to use TCHAR. Now i am finished changing every related char to TCHAR and left with 1 error which i asked ... Well yeh i am rewriting mfc VC++ code to VS2005(MFC)...so am facing promlems...m new to MFC... Now if ill change message back to char ill again get many errors so that means i have to change everything again....and would end up in never ending error loop.... Any other way out...? Thanks

      R CPalliniC D 3 Replies Last reply
      0
      • S Software_Specialist

        well i am well confused now. okay pls have a look over this post of mine where i discussed mainly about char variable... http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2073148&df=100&fr=26 Now all of them said me to use TCHAR in place of char or wchar_t.. I have not defined UNICODE...All of them said that TCHAR can handle both UNICODE nad non UNICODE ...So its always better to use TCHAR. Now i am finished changing every related char to TCHAR and left with 1 error which i asked ... Well yeh i am rewriting mfc VC++ code to VS2005(MFC)...so am facing promlems...m new to MFC... Now if ill change message back to char ill again get many errors so that means i have to change everything again....and would end up in never ending error loop.... Any other way out...? Thanks

        R Offline
        R Offline
        Rajkumar R
        wrote on last edited by
        #5

        Hi, Yes, It's nice choice of using generic text mapping function. So that you can compile both in unicode and non unicode version. Well C++ stream class has both version, whar_t version of "ifstream" is "wifstream", "cin" is "wcin", ... but i don't know the generic mapping for these class. map these classes yourself for unicode and other version. Best Regards Raj

        1 Reply Last reply
        0
        • S Software_Specialist

          well i am well confused now. okay pls have a look over this post of mine where i discussed mainly about char variable... http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2073148&df=100&fr=26 Now all of them said me to use TCHAR in place of char or wchar_t.. I have not defined UNICODE...All of them said that TCHAR can handle both UNICODE nad non UNICODE ...So its always better to use TCHAR. Now i am finished changing every related char to TCHAR and left with 1 error which i asked ... Well yeh i am rewriting mfc VC++ code to VS2005(MFC)...so am facing promlems...m new to MFC... Now if ill change message back to char ill again get many errors so that means i have to change everything again....and would end up in never ending error loop.... Any other way out...? Thanks

          CPalliniC Offline
          CPalliniC Offline
          CPallini
          wrote on last edited by
          #6

          Software_Specialist wrote:

          Now all of them said me to use TCHAR in place of char or wchar_t.. I have not defined UNICODE...All of them said that TCHAR can handle both UNICODE nad non UNICODE ...So its always better to use TCHAR.

          Well, they're right: actually TCHAR works both for UNICODE and not-UNICODE builds. The same is not true for ifstream that is a class specialized for handling char buffers. YOu can either follow my suggestion or accept the more elegant solution of Rajkumar_R [^]. :-D

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          In testa che avete, signor di Ceprano?

          1 Reply Last reply
          0
          • S Software_Specialist

            well i am well confused now. okay pls have a look over this post of mine where i discussed mainly about char variable... http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=2073148&df=100&fr=26 Now all of them said me to use TCHAR in place of char or wchar_t.. I have not defined UNICODE...All of them said that TCHAR can handle both UNICODE nad non UNICODE ...So its always better to use TCHAR. Now i am finished changing every related char to TCHAR and left with 1 error which i asked ... Well yeh i am rewriting mfc VC++ code to VS2005(MFC)...so am facing promlems...m new to MFC... Now if ill change message back to char ill again get many errors so that means i have to change everything again....and would end up in never ending error loop.... Any other way out...? Thanks

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #7

            Software_Specialist wrote:

            I have not defined UNICODE...

            This is the default for VS2005. Change ifstream to wifstream as has been mentioned.


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            S 1 Reply Last reply
            0
            • D David Crow

              Software_Specialist wrote:

              I have not defined UNICODE...

              This is the default for VS2005. Change ifstream to wifstream as has been mentioned.


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              S Offline
              S Offline
              Software_Specialist
              wrote on last edited by
              #8

              wifstream giving me linking errors....may be i need to change all the ifstream to wifstream....n ofstream to wofstream... trying to figure this out....

              D 1 Reply Last reply
              0
              • S Software_Specialist

                wifstream giving me linking errors....may be i need to change all the ifstream to wifstream....n ofstream to wofstream... trying to figure this out....

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #9

                Software_Specialist wrote:

                wifstream giving me linking errors...

                And those would be?


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                S 1 Reply Last reply
                0
                • D David Crow

                  Software_Specialist wrote:

                  wifstream giving me linking errors...

                  And those would be?


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  S Offline
                  S Offline
                  Software_Specialist
                  wrote on last edited by
                  #10

                  ok am getting 4 errors now... Error 27 error LNK2019: unresolved external symbol "public: void __thiscall hide_in_text::hide_file(class CProgressCtrl *)" (?hide_file@hide_in_text@@QAEXPAVCProgressCtrl@@@Z) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 28 error LNK2019: unresolved external symbol "public: void __thiscall secret_file_class::get_secret_file(void)" (?get_secret_file@secret_file_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 29 error LNK2019: unresolved external symbol "public: void __thiscall message_class::convert_to_bits(void)" (?convert_to_bits@message_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 30 fatal error LNK1120: 3 unresolved externals N:\ABC\Debug\ABC.exe

                  D R 2 Replies Last reply
                  0
                  • S Software_Specialist

                    ok am getting 4 errors now... Error 27 error LNK2019: unresolved external symbol "public: void __thiscall hide_in_text::hide_file(class CProgressCtrl *)" (?hide_file@hide_in_text@@QAEXPAVCProgressCtrl@@@Z) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 28 error LNK2019: unresolved external symbol "public: void __thiscall secret_file_class::get_secret_file(void)" (?get_secret_file@secret_file_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 29 error LNK2019: unresolved external symbol "public: void __thiscall message_class::convert_to_bits(void)" (?convert_to_bits@message_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 30 fatal error LNK1120: 3 unresolved externals N:\ABC\Debug\ABC.exe

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #11

                    Simply changing ifstream to wifstream caused these linker errors? :confused:


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    S 1 Reply Last reply
                    0
                    • D David Crow

                      Simply changing ifstream to wifstream caused these linker errors? :confused:


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      S Offline
                      S Offline
                      Software_Specialist
                      wrote on last edited by
                      #12

                      YEH thats true... Do you think it could be cos i am using TCHAR now. Whereas i guess wifstream supports wchar_t... Is there any class for TCHAR types...i dont think so..????

                      D 1 Reply Last reply
                      0
                      • S Software_Specialist

                        YEH thats true... Do you think it could be cos i am using TCHAR now. Whereas i guess wifstream supports wchar_t... Is there any class for TCHAR types...i dont think so..????

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #13

                        Software_Specialist wrote:

                        Do you think it could be cos i am using TCHAR now.

                        No, because the preprocessor has resolved those to wchar_t.


                        "A good athlete is the result of a good and worthy opponent." - David Crow

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        S 1 Reply Last reply
                        0
                        • D David Crow

                          Software_Specialist wrote:

                          Do you think it could be cos i am using TCHAR now.

                          No, because the preprocessor has resolved those to wchar_t.


                          "A good athlete is the result of a good and worthy opponent." - David Crow

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          S Offline
                          S Offline
                          Software_Specialist
                          wrote on last edited by
                          #14

                          okay These were my main problems cos of which i first used wchar_t and now TCHAR... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' TCHAR strFilter[1000]; _tcscpy_s(strFilter, "All Files (*.*)|*.*||"); And error i got is none of the 2 overloads could convert all the arguments type. If i get some other way to deal with this situation... I mean without using wchar_t or TCHAR or L or _T or wcscpy or _tcscpy_s etc etc...then it might work...Dont know really..lez c ..m playing around with it at the moment... Thanks

                          D S 2 Replies Last reply
                          0
                          • S Software_Specialist

                            okay These were my main problems cos of which i first used wchar_t and now TCHAR... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' TCHAR strFilter[1000]; _tcscpy_s(strFilter, "All Files (*.*)|*.*||"); And error i got is none of the 2 overloads could convert all the arguments type. If i get some other way to deal with this situation... I mean without using wchar_t or TCHAR or L or _T or wcscpy or _tcscpy_s etc etc...then it might work...Dont know really..lez c ..m playing around with it at the moment... Thanks

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #15

                            Software_Specialist wrote:

                            _tcscpy_s(strFilter, "All Files (*.*)|*.*||");

                            Doesn't this require three arguments? The string literal needs to use _T() or L. In any case, do you really need to use wchar_t variables?


                            "A good athlete is the result of a good and worthy opponent." - David Crow

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            S 1 Reply Last reply
                            0
                            • S Software_Specialist

                              okay These were my main problems cos of which i first used wchar_t and now TCHAR... char str[10]; CString Password; strcpy(str, Password); In above code i get error saying can not convert parameter 2 from 'CString to const char*' TCHAR strFilter[1000]; _tcscpy_s(strFilter, "All Files (*.*)|*.*||"); And error i got is none of the 2 overloads could convert all the arguments type. If i get some other way to deal with this situation... I mean without using wchar_t or TCHAR or L or _T or wcscpy or _tcscpy_s etc etc...then it might work...Dont know really..lez c ..m playing around with it at the moment... Thanks

                              S Offline
                              S Offline
                              Software_Specialist
                              wrote on last edited by
                              #16

                              i guess i got some cause due to which its giving me these error...ill make those changes n will see if it works or not... i would post wtever i get in a bit...

                              1 Reply Last reply
                              0
                              • S Software_Specialist

                                ok am getting 4 errors now... Error 27 error LNK2019: unresolved external symbol "public: void __thiscall hide_in_text::hide_file(class CProgressCtrl *)" (?hide_file@hide_in_text@@QAEXPAVCProgressCtrl@@@Z) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 28 error LNK2019: unresolved external symbol "public: void __thiscall secret_file_class::get_secret_file(void)" (?get_secret_file@secret_file_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 29 error LNK2019: unresolved external symbol "public: void __thiscall message_class::convert_to_bits(void)" (?convert_to_bits@message_class@@QAEXXZ) referenced in function "public: void __thiscall CABCDlg::OnHide(void)" (?OnHide@CABCDlg@@QAEXXZ) ABCDlg.obj Error 30 fatal error LNK1120: 3 unresolved externals N:\ABC\Debug\ABC.exe

                                R Offline
                                R Offline
                                Rajkumar R
                                wrote on last edited by
                                #17

                                Hi, These errors or not due to TCHAR or wifstream. Have you included the file with the definition for hide_in_text::hide_file, secret_file_class::get_secret_file, ... I think the definition for these are missing. Best Regards Raj

                                S 1 Reply Last reply
                                0
                                • D David Crow

                                  Software_Specialist wrote:

                                  _tcscpy_s(strFilter, "All Files (*.*)|*.*||");

                                  Doesn't this require three arguments? The string literal needs to use _T() or L. In any case, do you really need to use wchar_t variables?


                                  "A good athlete is the result of a good and worthy opponent." - David Crow

                                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                  S Offline
                                  S Offline
                                  Software_Specialist
                                  wrote on last edited by
                                  #18

                                  # Doesn't this require three arguments? No it was working ...So i guess its right...anyway i think i hv some problem in one of my function so ill try to modify it a bit....

                                  D 1 Reply Last reply
                                  0
                                  • S Software_Specialist

                                    # Doesn't this require three arguments? No it was working ...So i guess its right...anyway i think i hv some problem in one of my function so ill try to modify it a bit....

                                    D Offline
                                    D Offline
                                    David Crow
                                    wrote on last edited by
                                    #19

                                    Software_Specialist wrote:

                                    No it was working ...So i guess its right

                                    So what of your "And error i got is none of the 2 overloads could convert all the arguments type." comment? That does not sound like it is working, or right, to me.


                                    "A good athlete is the result of a good and worthy opponent." - David Crow

                                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                    S 1 Reply Last reply
                                    0
                                    • R Rajkumar R

                                      Hi, These errors or not due to TCHAR or wifstream. Have you included the file with the definition for hide_in_text::hide_file, secret_file_class::get_secret_file, ... I think the definition for these are missing. Best Regards Raj

                                      S Offline
                                      S Offline
                                      Software_Specialist
                                      wrote on last edited by
                                      #20

                                      Yeh you are right...thats what i am doing now.. declaration was missing...by mistake it got deleted... I am rewriting those 2 functions now.....ill update whatever i get by the end... Thanks a lot for all your help...

                                      1 Reply Last reply
                                      0
                                      • D David Crow

                                        Software_Specialist wrote:

                                        No it was working ...So i guess its right

                                        So what of your "And error i got is none of the 2 overloads could convert all the arguments type." comment? That does not sound like it is working, or right, to me.


                                        "A good athlete is the result of a good and worthy opponent." - David Crow

                                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                        S Offline
                                        S Offline
                                        Software_Specialist
                                        wrote on last edited by
                                        #21

                                        oh by that i meant to say it was working like this... CString strFilter; const TCHAR *strSource= _T("All Files (*.*)|*.*||"); _tcscpy_s(strFilter, strSource); So Parameter isn't a problem in that...

                                        D 1 Reply Last reply
                                        0
                                        • S Software_Specialist

                                          oh by that i meant to say it was working like this... CString strFilter; const TCHAR *strSource= _T("All Files (*.*)|*.*||"); _tcscpy_s(strFilter, strSource); So Parameter isn't a problem in that...

                                          D Offline
                                          D Offline
                                          David Crow
                                          wrote on last edited by
                                          #22

                                          Software_Specialist wrote:

                                          CString strFilter; const TCHAR *strSource= _T("All Files (*.*)|*.*||"); _tcscpy_s(strFilter, strSource);

                                          :confused: How is this not generating a compiler error? I would have expected it to be:

                                          _tcscpy_s(strFilter.GetBuffer(128), strSource);

                                          In any case, why would you want to use _tcscpy_s() with a CString object? That makes no sense.


                                          "A good athlete is the result of a good and worthy opponent." - David Crow

                                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                                          S 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups