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. C and Visual C++

C and Visual C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
9 Posts 5 Posters 0 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.
  • A Offline
    A Offline
    aleyah
    wrote on last edited by
    #1

    Hello.. I want to know something! In Visual C++ also can use C code, but can or not C code in same project call C++ function?? like this, my C code is in what.c and I want to call function in loginDlg.C++, the function name is CLoginDLg... i try do this in file what.c CLoginDlg dlg; dlg.DoModal(); but this error appear when i compile it error C2065: 'CLoginDlg' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'dlg' error C2065: 'dlg' : undeclared identifier error C2224: left of '.DoModal' must have struct/union type anybody can help me.. or i do wrong!!??

    S A 2 Replies Last reply
    0
    • A aleyah

      Hello.. I want to know something! In Visual C++ also can use C code, but can or not C code in same project call C++ function?? like this, my C code is in what.c and I want to call function in loginDlg.C++, the function name is CLoginDLg... i try do this in file what.c CLoginDlg dlg; dlg.DoModal(); but this error appear when i compile it error C2065: 'CLoginDlg' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'dlg' error C2065: 'dlg' : undeclared identifier error C2224: left of '.DoModal' must have struct/union type anybody can help me.. or i do wrong!!??

      S Offline
      S Offline
      Simon Walton
      wrote on last edited by
      #2

      If you post some code perhaps we can help you. :) Simon C++: Only friends can see your private parts. Sonork ID 100.10024

      A 1 Reply Last reply
      0
      • S Simon Walton

        If you post some code perhaps we can help you. :) Simon C++: Only friends can see your private parts. Sonork ID 100.10024

        A Offline
        A Offline
        aleyah
        wrote on last edited by
        #3

        where to i post my code in this forum??

        1 Reply Last reply
        0
        • A aleyah

          Hello.. I want to know something! In Visual C++ also can use C code, but can or not C code in same project call C++ function?? like this, my C code is in what.c and I want to call function in loginDlg.C++, the function name is CLoginDLg... i try do this in file what.c CLoginDlg dlg; dlg.DoModal(); but this error appear when i compile it error C2065: 'CLoginDlg' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'dlg' error C2065: 'dlg' : undeclared identifier error C2224: left of '.DoModal' must have struct/union type anybody can help me.. or i do wrong!!??

          A Offline
          A Offline
          Alvaro Mendez
          wrote on last edited by
          #4

          You can't call C++ code from C the way you're trying it. CLoginDlg is a class which C does not recognize. What you can do is wrap that code inside a global "C"-style function inside your C++ file:

          extern "C" void OpenLoginDlg()
          {
          CLoginDlg dlg;
          dlg.DoModal();
          }

          Then you can call OpenLoginDlg in your C code. Regards, Alvaro

          A 2 Replies Last reply
          0
          • A Alvaro Mendez

            You can't call C++ code from C the way you're trying it. CLoginDlg is a class which C does not recognize. What you can do is wrap that code inside a global "C"-style function inside your C++ file:

            extern "C" void OpenLoginDlg()
            {
            CLoginDlg dlg;
            dlg.DoModal();
            }

            Then you can call OpenLoginDlg in your C code. Regards, Alvaro

            A Offline
            A Offline
            aleyah
            wrote on last edited by
            #5

            never mind for login dialog... but i want you to solve this problem... because this i my main problem........ this is my C code case IDC_OK: database db; //this i call function from c++ file db.Open(CRecordset::dynaset,"password); while(!db.IsEOF()) { if(db.m_userID == IDC_USER_NAME) { if(db.m_password == IDC_PASSWORD) { ShellExecute (NULL, "open", "d:\\games\\Same.exe",NULL,NULL,SW_SHOWNA); exit(0); } else { AfxMessageBox("Incorrect password!"); m_word=""; UpdateData(false); return; } } loginConn.MoveNext(); } but this error appear error C2065: 'database' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'db' error C2065: 'db' : undeclared identifier error C2224: left of '.Open' must have struct/union typeerror C2065: 'CRecordset' : undeclared identifier error C2143: syntax error : missing ')' before ':'

            A 1 Reply Last reply
            0
            • A aleyah

              never mind for login dialog... but i want you to solve this problem... because this i my main problem........ this is my C code case IDC_OK: database db; //this i call function from c++ file db.Open(CRecordset::dynaset,"password); while(!db.IsEOF()) { if(db.m_userID == IDC_USER_NAME) { if(db.m_password == IDC_PASSWORD) { ShellExecute (NULL, "open", "d:\\games\\Same.exe",NULL,NULL,SW_SHOWNA); exit(0); } else { AfxMessageBox("Incorrect password!"); m_word=""; UpdateData(false); return; } } loginConn.MoveNext(); } but this error appear error C2065: 'database' : undeclared identifier error C2146: syntax error : missing ';' before identifier 'db' error C2065: 'db' : undeclared identifier error C2224: left of '.Open' must have struct/union typeerror C2065: 'CRecordset' : undeclared identifier error C2143: syntax error : missing ')' before ':'

              A Offline
              A Offline
              aleyah
              wrote on last edited by
              #6

              anyone can help me!!!!

              J N 2 Replies Last reply
              0
              • A Alvaro Mendez

                You can't call C++ code from C the way you're trying it. CLoginDlg is a class which C does not recognize. What you can do is wrap that code inside a global "C"-style function inside your C++ file:

                extern "C" void OpenLoginDlg()
                {
                CLoginDlg dlg;
                dlg.DoModal();
                }

                Then you can call OpenLoginDlg in your C code. Regards, Alvaro

                A Offline
                A Offline
                aleyah
                wrote on last edited by
                #7

                i do as you write... but when i compile... it have this warning want.c(1957) : warning C4013: 'OpenLoginDlg' undefined; assuming extern returning int and i try to build exe... it appear Microsoft Visual C++ Debug Library... so what must i do now??

                1 Reply Last reply
                0
                • A aleyah

                  anyone can help me!!!!

                  J Offline
                  J Offline
                  Joaquin M Lopez Munoz
                  wrote on last edited by
                  #8

                  Do not panic :) Try this:

                  1. close all open files in your Visual Studio, delete your .c files from the project, go to the Windows Explorer, locate those files, change the extension to .cpp and add them back to the project. Now, hopefully, your formerly C modules are C++.
                  2. whenever you get some "undeclared identifier" compiler error, try to locate the .h header file for the class you're trying to use and insert the corresponding #include.

                  With a little luck, this will help you advance a little further. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

                  1 Reply Last reply
                  0
                  • A aleyah

                    anyone can help me!!!!

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #9

                    Sounds like the best help for you would be to go back to school or re-read the books.

                    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