0
votes

I'm moving a load of old code over to our new frame work, one section of this old code uses some MFC classes.

When trying to compile the class I am getting the error(s):

error C2504: 'CObject' : base class undefined
error C3861: 'VERIFY': identifier not found
error C3861: 'ASSERT': identifier not found 
....

In my solution: properties -> General I have Use MFC in shared dll (I've also tried statically linking) General -> Charater set: Use Multi-Byte Character Set C/C++-> Precompiled headers -> Use

C/C++->Advanced Show includes YES

I'm including stdafx.h first on all files. I have afx.h and afxwin.h in stdafx.h (I've tried different orders and only including afxwin.h)

my stdafx.h

#pragma once
#include <afx.h>
#include <afxwin.h>   // MFC core and standard components

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>

The header file of the problem class

// blocksock.h

#include "stdafx.h"
#include <atlstr.h>

#include "winsock.h"
#include <string>

the includes of the .cpp of class

#include "stdafx.h"
#include "blocksock.h"

The first header to be shown to be included is:

\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlstr.h

The last include to be shown tobe included is:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\share.h

When I look at the command line I can see that it has the correct path to afx.h

I'm using VS2010.

What the hell is going on!!! It can see the MFC file but does not seem to recognize the class that is define within.

Note: I just tried swapping to

General -> Charater set: Use Unicode Character Set

as I noticed a comment in afx.h about being based on wchar_t

and instead of the above error gotloads of errorsabout MFC include files like this.

1>  Note: including file:         C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\atlalloc.h
1>c:\program files (x86)\microsoft visual studio 10.0\vc\atlmfc\include\atlconv.h(776): error C2440: 'return' : cannot convert from 'LPCTSTR' to 'LPCOLESTR'
2
Can you build a simple MFC project created from scratch ? - Jabberwocky
this was going to be my next plan of attack, the wizard seems to force me to a windowed project, I just want a console. - Tommy
Try anyway and look if it compiles. - Jabberwocky
That final error sounds like LPCTSTR and LPCOLESTR use different base types (wchar_t vs. unsigned short). This not a problem, unless wchar_t is treated as a built-in type (Compiler option /Zc:wchar_t (wchar_t Is Native Type)). Changing this setting to "No" should fix that final error. - IInspectable
Sorry for the late reply been on holiday away from internet. In the end I created a new MFC project, got that compiled, then stated with a clean console project and added in all the dependencies in the stdafx.h. Eventually got it running. Turned out the old project had a lot of stuff set up as multi byte as well rather than unicode. After a lot of tidying it eventually worked! - Tommy

2 Answers

1
votes

I had a similar problem and I think the better way in this case is to create a new MFC project, and migrate the files. Looks like a big job but you gonna waste less time than trying to resolve every dependency problem.

1
votes

Posting for people like me who did not find answers in this thread, here's additionnal info that may help you out.

I had a similar problem, I included stdafx.h in both the .h and the .cpp, updated Visual Studio service pack 1 and made sure all my projects' "Use of MFC" were set as "Use MFC in a shared DLL" (in Properies/Configuration Properties/General)

If you haven't tried any of the three solutions above you should give it a try.