|
When I specify msvcrtd.lib, I get the following errors:
Linking...
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusDoc::classCExodusDoc" (?classCExodusDoc@CExodusDoc@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CMainFrame::classCMainFrame" (?classCMainFrame@CMainFrame@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusView::classCExodusView" (?classCExodusView@CExodusView@@2UCRuntimeClass@@B)
msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/Exodus.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
Exodus.exe - 5 error(s), 0 warning(s)
----------------------------------------------------------
The funny thing is that the program was working fine the first time I created it, then when I went to reopen the project...no go. It's got to be something simple. I'm reading a bunch of stuff on Google, but nothing to solve this problem yet.
Also, I did go into "options/directories" to specify the path to the library on my hardrive containing the msvcrtd file.
|
|
|
|
|
Your error has nothing to do with finding the msvcrtd.lib file. I believe that you are not getting the errors when you specify just msvcrtd because it is looking for msvcrtd.obj and it does not display the other errors because of the missing file. Did you try a build clean?
John
|
|
|
|
|
Yes, this is the message I receive...
Linking...
LINK : fatal error LNK1104: cannot open file "msvcrtd.obj"
Error executing link.exe.
Exodus.exe - 1 error(s), 0 warning(s)
I'm not sure what the problem is...I've searched Google for an hour.
|
|
|
|
|
You get this error because you are telling the compiler that you have a "msvcrtd.obj" to link with in your linker settings by not including the extension. Because vc++ does not have a "msvcrtd.obj" it is not found and the linker displays this error and ends. It does not display the other 5 errors because it assumes they are a result of the missing file. This behavior is similar to including a header file in a cpp file that does not exist.
John
|
|
|
|
|
I really appreciate your input on this John, thanks. I'm not exactly sure what I need to do at this point. If I remove the "msvcrdt" addition from the project/settings/link/library...I get the following errors...
Linking...
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusDoc::classCExodusDoc" (?classCExodusDoc@CExodusDoc@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CMainFrame::classCMainFrame" (?classCMainFrame@CMainFrame@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusView::classCExodusView" (?classCExodusView@CExodusView@@2UCRuntimeClass@@B)
msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/Exodus.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
Exodus.exe - 5 error(s), 0 warning(s)
-----------------------------------------------
with just the file "msvcrdt" typed in (with no extension), I get the following error...
Linking...
LINK : fatal error LNK1104: cannot open file "msvcrdt.obj"
Error executing link.exe.
Exodus.exe - 1 error(s), 0 warning(s)
What should I do on this? Thanks again.
|
|
|
|
|
DaveE9th wrote:
msvcrdt
This is spelt wrong - it should be "msvcrtd", and you need to specify the extension - .lib
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
Ryan,
When I type in "msvcrtd.lib", I get the following error messages:
Linking...
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusDoc::classCExodusDoc" (?classCExodusDoc@CExodusDoc@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CMainFrame::classCMainFrame" (?classCMainFrame@CMainFrame@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusView::classCExodusView" (?classCExodusView@CExodusView@@2UCRuntimeClass@@B)
msvcrtd.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
Debug/Exodus.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.
Exodus.exe - 5 error(s), 0 warning(s)
|
|
|
|
|
As John said, the first 3 errors seem to suggest that you don't have IMPLEMENT_DYNCREATE() in the .cpp for the CExodusDoc, CMainFrame and CExodusView classes. The fourth error generally occurs because you're trying to compile a Win32 GUI application as though it's a Win32 console application, ie. you've stuffed up the project settings (probably not intentionally)
Check that the IMPLEMENT_DYNCREATE() lines are there, and put them in if they're not. To fix the last problem, Go to the Link tab of your project settings. In the edit box at the bottom, make sure you have "/subsystem:windows". If you have a different /subsystem, then change it. If it's not there then add it in.
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
The first four errors are because you don't have IMPLEMENT_DYNAMIC or IMPLEMENT_DYNCREATE in your cpp file for CExodusDoc, CMainFrame, AND CExodusView I believe. I also believe the last error is because you are linking a crt library with a mfc program.
John
|
|
|
|
|
John,
Thanks for your input. All I know is that I created an MFC program from scratch (a database program), closed it for the day, and then couldn't open it anymore. What might I do to get my program open again? When I type in the "msvcrtd", I only get one error message..."missing msvcrtd.obj" What is my program looking for if not the crt library?
Thanks
Dave
|
|
|
|
|
DaveE9th wrote:
When I type in the "msvcrtd", I only get one error message..."missing msvcrtd.obj" What is my program looking for if not the crt library?
You should remove this line from the project settings. As I said before when you add this line you only get one error because the linker stops when it cannot find "msvcrtd.obj". Adding this line is in no way the solution to your problem. Does this only happen in debug build or does it also happen in release? What compiler are you using VC5, VC6, VC.NET? I tried to reproduce your errors but I could not. Did you try deleting the Debug and Release directories and do a full rebuild?
[EDIT]
Look at Ryan's answer here: http://www.codeproject.com/script/comments/forums.asp?msg=542658&forumid=1647#xx542658xx[^]
It contains the best explanation on why you get the errors.
[/EDIT]
John
|
|
|
|
|
I am using VC++ 6. I have cleaned both the debug and release directories and did a complete rebuild. This is what I now get:
Linking...
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusDoc::classCExodusDoc" (?classCExodusDoc@CExodusDoc@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CMainFrame::classCMainFrame" (?classCMainFrame@CMainFrame@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusView::classCExodusView" (?classCExodusView@CExodusView@@2UCRuntimeClass@@B)
Debug/Exodus.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
-----------------------------------------------------
I changed the subsystem setting to "windows", it was set to "console". I also see that my classes did not open with the workspace when I reopened the program (I think this is my problem), problem is I'm not sure how to open them (shouldn't they open with the workspace?). The only class showing up in my class view is "CAboutDlg". I've read the VC++ 6 help menu but didn't see anything so I'm going to keep reading 'til I find something.
Thanks for your patience, I'll get the hang of this. I'm trying to follow a database tutorial in Ivor Horton's book on VC++. Once I figure out how to eliminate these little quirks in VC++, I should be off to a good start. I just received Jeff Prosise's book on "MFC programming" in the mail and hope that will clear some things up.
Dave
|
|
|
|
|
DaveE9th wrote:
I also see that my classes did not open with the workspace when I reopened the program (I think this is my problem), problem is I'm not sure how to open them (shouldn't they open with the workspace?).
Delete the clw file and ncb files.
John
|
|
|
|
|
DaveE9th wrote:
Linking...
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusDoc::classCExodusDoc" (?classCExodusDoc@CExodusDoc@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CMainFrame::classCMainFrame" (?classCMainFrame@CMainFrame@@2UCRuntimeClass@@B)
Exodus.obj : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CExodusView::classCExodusView" (?classCExodusView@CExodusView@@2UCRuntimeClass@@B)
Debug/Exodus.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.
The three errors are because you don't have the macros for dynamic class creation in your cpp files.
You must have:
IMPLEMENT_DYNCREATE(CExodusDoc, CDocument)
in your ExodusDoc.cpp file
You must have:
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
in your MainFrm.cpp file
You must have
IMPLEMENT_DYNCREATE(CExodusView,CView)
in your ExodusView.cpp file. In this case CView may be different check to see what the base class for CExodusView.
John
|
|
|
|
|
I finally got my program working. I really appreciate the help (and patience). The problem was that I didn't have many of my program files opened, they weren't even listed in the workspace window. I was under the assumtion that the .dsw file would open everything, evidently it does not. I had to reopen all the files manually by using the "SHIFT" key to highlight all of them and then insert them into the program. I don't understand why opening a workspace file (.dsw) wouldn't open everything as the name implies. We'll, I learned a lot here.
Thanks much, Dave
|
|
|
|
|
It was a very simple problem. Being a newbie to VC++, I didn't realize that sometimes the header files don't load with the source files. All of the implementations that you mentioned John were missing because my classes were missing. I had to go to "Project/Insert files" and insert the header files to solve the problem.
Thanks for your patience,
Dave
"The man who reads nothing is better educated than the man who reads nothing but newspapers."- Thomas Jefferson
|
|
|
|
|
I have created a pager control. Can you tell me how to assigned the application toolbar to the pager control? The documentation says touse PGM_SETCHILD, but I don't know how to implement.
Eilzabeth
|
|
|
|
|
1. Create the pager control.
2. Create the toolbar with parent set to the pager control.
3. ::SendMessage( hWndPager, PGM_SETCHILD, 0, hWndToolbar );
Magnus
|
|
|
|
|
I created the pager control successfully. Then I tried to create the toolbar using the return handle from the pager control. When I ran the application, I got an Assertion Failed error at m_wndToolBar.Create function. Can you examin the code below?
HWND h_pager_control = CreatePagerControl();
if ( h_pager_control == NULL)
return -1;
//the toolbar - try to set it as a child of the pager control
if (!m_wndToolBar.Create((CWnd*)h_pager_control) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
My problem might be in converting h_pager_control to CWnd*.
Eilzabeth
|
|
|
|
|
Yes that is correct you cant cast a HWND to a CWnd*.
I dont use MFC, så I dont know if the pager control is available or not.
But if its not, the you can create a pure CWnd object and call Attach( h_pager_control). Then you can pass that CWnd to toolBar.Create(). Just be sure to to save the CWnd object as long your pager control lives.
And one more thing, dont write if's like you did above, its hard to read and it can be hard for persons not so familiar with C++ to know what will happen. Splitt the two function calls into 2 if's, that way you will get better error handling also.
And if you want more tips, dont use C cast's use C++ casts ( reinterpret_cast, static_cast, const_cast and dynamic_cast )
Magnus
|
|
|
|
|
I got most of the code working. How can I get a handle to the toolbar hWndToolbar?
Eilzabeth
|
|
|
|
|
CWnd has a function called GetSafeHwnd(). And CToolbar is inherited from CWnd.
Magnus signing off for tonight
|
|
|
|
|
Thank you very much for walking me through. I am able to run the following code without runtime error. But I do not see the toolbar. Am I missing some steps?
//the pager control
HWND h_pager_control = CreatePagerControl();
if ( h_pager_control == NULL)
return -1;
//the toolbar - try to set it as a child of the pager control
m_wnd_pager.Attach(h_pager_control);
if (!m_wndToolBar.Create(&m_wnd_pager) )
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to load menu to toolbar\n");
return -1; // fail to create
}
::SendMessage( h_pager_control, PGM_SETCHILD, 0, (LPARAM)m_wndToolBar.GetSafeHwnd() );
Eilzabeth
|
|
|
|
|
Do you create your pager control with WS_VISIBLE style, otherwise you have to call ::ShowWindow( h_pager_control, SW_SHOW );
Did you remember to set the pager control's parent to the window that should show it?
I dont know if your comment is wrong for the LoadToolBar function, but you cant load menus to a toolbar. You can only load toolbar resource templates.
And depending on when you create your controls, you could have to call InvalidateRect( NULL ) on the pager control's parent (not sure about this tip, as Im not very familiar with MFC).
Magnus
|
|
|
|
|
I added style WS_VISIBLE to the pager control and ran it. Still the toolbar is not visible.
I created the pager control from the frame window CMainFrame. So the pager control should be visible from all child windows. See code below:
HWND CMainFrame::CreatePagerControl()
{
//create the pager control
//initialize page control object
LPINITCOMMONCONTROLSEX lpInitCtrls = new INITCOMMONCONTROLSEX;
lpInitCtrls->dwICC =ICC_PAGESCROLLER_CLASS;
lpInitCtrls->dwSize = sizeof(INITCOMMONCONTROLSEX);
InitCommonControlsEx(lpInitCtrls);
HWND h_pager_control = CreateWindow(WC_PAGESCROLLER,NULL,PGS_HORZ|WS_CHILD|WS_VISIBLE, 0, 0, 0, 0, m_hWnd, NULL ,AfxGetInstanceHandle(),NULL);
if ( h_pager_control == NULL)
{
LPVOID lpMsgBuf;
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL);
AfxMessageBox((LPCTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
}
return h_pager_control;
}
My comments are wrong. It should say can not load toolbar resouce instead of menu resource.
I am not sure about your last question. I added InvalidateRect(NULL)after the pager control was created. It did not help. The pager control is still not visible.
Eilzabeth
|
|
|
|