You are currently viewing the BOOK: Ivor Horton's Beginning Visual C++ 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
Has anybody else run into the LNK2019 issue related to CString and using DLLs? I've tried to fix it the way that MS says to do so(http://support.microsoft.com/kb/309801/en-us), but I just can't get it to work. Anybody solve this problem? Seems that it's an issue using the new CString template class vs the old CString class.
I'm getting back this error:
SketcherView.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall CText::CText(class CPoint,class CPoint,class ATL::CStringT<char,class StrTraitMFC_DLL<char,class ATL::ChTraitsCRT<char> > >,unsigned long)" (__imp_??0CText@@QAE@VCPoint@@0V?$CStringT@DV?$Str TraitMFC_DLL@DV?$ChTraitsCRT@D@ATL@@@@@ATL@@K@Z) referenced in function "public: void __thiscall CSketcherView::OnLButtonDown(unsigned int,class CPoint)" (?OnLButtonDown@CSketcherView@@QAEXIVCPoint@@@Z)
It refers to the CText call on lines 199-200 in the SketcherView.cpp file. I don't know if the knowledge base article applies or not. The CText function call exists in the Elements.cpp file for the ExtDLLExample DLL.
I went through Chapter 18 about 6 months ago, so unable to recall all that I did. I have, though, found my project files and re-compiled them and Sketcher still works fine. (I did wonder about one aspect; Visual Studio 2005 had a -what seemed -fairly major set of changes recently, so I thought perhaps that was the cause, but evidently not so.)
I suggest using a compare utility to compare your code listing for each file against those in the downloadable exercises and answers. If you look at my posting: P2P Forum > Books > Ivor Horton's Beginning Visual C++ 2005 > Comparing Files... , I found one that suited me and may help you. I did find that some minute typos on my part caused me major problems...
I ended up redoing both the Sketcher and the ExtDLLExample projects from scratch using the source code provided by the website with the exact same results. I am at a total loss as to what is wrong with the projects. I've even contacted Ivor Horton with no luck. He says the same thing. I must've missed a step in the set-up or something.
Well, I would still try something like "Files Comparer".
Another possibility is that something in your Visual Studio installation has been corrupted. If you have someone local to you who runs VS, perhaps try taking your complete project file and compiling it on their installation.
I had exactly the same problem as you with the CText class. I couldn't work out why and when I saw your post I gave up on it and moved the CText class back to the program leaving everything else in the dll.
Anyway, I ran into another problem which I recently posted. In solving that one I seem to have solved the problem I was having with CText. I don't know if the solution will work for you as well but it's worth a try.
The problem seems to be related to the versions of the MFC libraries that the program and the dll link to. It seems that when you create a dll project using the application wizard it chooses by default to use the unicode character set. If you did the same thing as me, when you created your Sketcher application using the wizard you unchecked the unicode libraries box following Mr Horton's advice for the text editor (page 658). I guess because I didn't really understand it, I thought it safer to do the same thing for the Sketcher application.
Anyway, you may find if you bring up the project properties page for the Sketcher application, select the 'Use unicode character set' in the 'Character Set' option and rebuild your project that the problem disappears. It did with me.
If you look in the 'stdafx.h' header file for Sketcher and go to the bottom, you'll see that if _UNICODE is defined it seems to link with a different version of the control set (MFC libraries?). Perhaps this explains the problem. You'll probably also find your Sketcher program starts to look a bit more Windows XP than Windows 98. The dialogue boxes certainly look better and so do the toolbars and window frames.
The main thing, it seems, is to make sure that the program and dll link to the same set of MFC. You can use the unicode or multi-byte character set as long as the same option is selected for both the program and the dll.
Anyway, hopefully it will sort the problem out for you. Let me know if it does.
That's it!!! I'm glad that you figured this out and I truly appreciate the information. I'd gone to the extent of contacting Ivor Horton directly and he couldn't figure out what was wrong either.
Again, thanks so much for the information. I needed this example in order to make a DLL for a project that I am working on. You are a lifesaver.
I had the exact problem while going through Chapter 18, and your solution just saved me a lot of time. This is probably something that should be printed in the errata.
Kudos for posting the solution and thanks for the help!
Location: Gateshead, Tyne and Wear, United Kingdom.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Dan6,
You also solved it for me. I had exactly the same problem and it was driving me nuts as well. I've even posted to this forum about it but didn't see your post until I searched for the error message.
Thanks a lot. I don't know how you figured that one out.