C and Visual C++
-
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!!??
-
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!!??
If you post some code perhaps we can help you. :) Simon C++: Only friends can see your private parts. Sonork ID 100.10024
-
If you post some code perhaps we can help you. :) Simon C++: Only friends can see your private parts. Sonork ID 100.10024
-
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!!??
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
-
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
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 ':'
-
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 ':'
-
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
-
Do not panic :) Try this:
- 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++.
- 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
-
Sounds like the best help for you would be to go back to school or re-read the books.