Link to home
Start Free TrialLog in
Avatar of thready
thready

asked on

Can't compile

Hi Experts,
I'm again trying to compile an old piece of code I did in Visual C++ 6.0 - now in Visual C++ 2008 Pro.  I have the following additional include folders:
C:\WinDDK\7600.16385.0\inc\api;C:\WinDDK\7600.16385.0\inc\ddk;C:\WinDDK\7600.16385.0\inc\crt;C:\WinDDK\7600.16385.0\inc\atl71;c:\WinDDK\7600.16385.0\bin\x86\OACR

I'm getting these errors - any ideas?
Thanks!

>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(736) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(737) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(737) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(738) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(739) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(739) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(773) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(774) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(774) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(947) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(948) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(948) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1003) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1004) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1004) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1139) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1139) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1139) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1504) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1504) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(1504) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(841) : error C2061: syntax error : identifier '_In_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(841) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(841) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(858) : error C2061: syntax error : identifier '_Out_opt_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(859) : error C2061: syntax error : identifier '_Out_opt_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(901) : error C2061: syntax error : identifier '_In_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(902) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(902) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(903) : error C2061: syntax error : identifier '_In_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(904) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(904) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(904) : error C2535: 'int CDC::Escape(void)' : member function already defined or declared
1>        c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(901) : see declaration of 'CDC::Escape'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(1165) : error C2061: syntax error : identifier '_In_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(1166) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(1166) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : error C2065: '_Inout_' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : error C2146: syntax error : missing ')' before identifier 'CDataExchange'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : warning C4229: anachronism used : modifiers on data are ignored
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : error C2182: 'DDX_Text' : illegal use of type 'void'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : error C2365: 'DDX_Text' : redefinition; previous definition was 'function'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxdd_.h(39) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2238) : error C2061: syntax error : identifier '_Out_z_cap_post_count_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2238) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2238) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2389) : error C2061: syntax error : identifier '_Inout_z_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2391) : error C2061: syntax error : identifier '_Inout_z_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwin.h(2394) : error C2061: syntax error : identifier '_Out_z_cap_c_'
1>c:\program files\microsoft visual s
Avatar of AnilKumarSharma
AnilKumarSharma
Flag of India image

Avatar of Zoppo
Hi thready,

I just took a look where '_Out_z_cap_' is declared and how it is included:

- declared in 'sal.h'
- 'sal.h' is included in 'new.h' if these two preprocessor defines doesn't exist: _INC_NEW, _MSC_EXTENSIONS
- 'new.h' is included in 'afx.h' if this preprocessor define doesn't exist: _INC_NEW

So, IMO the only reason at least the first error could be that either _INC_NEW or _MSC_EXTENSIONS is defined before 'afx.h' (or 'afxwin.h') is included. Please check if '#include <afxwin.h>' is the first include in your 'stdafx.h' and if one of the two mentioned defines are declared in the project's compile settings.

Hope that helps,

ZOPPO
Avatar of js-profi
js-profi

i currently have afx.h from vs2003 only. could you double-click on the first error and post some snippet of code around the first error - say 20 lines before and 10 after. also check the path of the afx.h (put the mouse cursor above the editor tab until path was shown) that it is of correct version vs2008.
Avatar of thready

ASKER

Hi Zoppo,
<afxwin.h> is the first item included in stdafx.h.  How do I check that _INC_NEW is defined?
Hm - you could either check the compiler settings or add this code befor the #include <afxwin.h> in your stdafx.h:

> #ifdef _INC_NEW
> #error _INC_NEW already defined
> #endif
> #ifdef _MSC_EXTENSIONS
> #error _MSC_EXTENSIONS already defined
> #endif

ZOPPO
Avatar of thready

ASKER

js - c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h
Avatar of thready

ASKER

Zoppo - now I get the error - _MSC_EXTENSIONS already defined.
ok, sorry, I think I made a mistake regarding '_MSC_EXTENSIONS' - this one is always defined when compiling with the '/Ze'
option (Enable Language Extensions) which is on by default.

It maybe you compile the file as a C file, not as a C++

To check this open the 'Properties' for the file which generates this error when compiled, open options for 'Advanced' and check the 'Compile As' option.

ZOPPO
Avatar of thready

ASKER

Zoppo - the file that generates this error is:  c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h

I should compile this one as a C file?
No, I meant the file which is compiled - the error appears in 'afx.h', but it appears while a .cpp file of your project is compiled.

The file's name should be shown in the line above the first error message ...
Avatar of thready

ASKER

It's stdafx.h.  When I compile it as a C file, I get this error:  (comes from afx.h again)....

#ifndef __cplusplus
      #error MFC requires C++ compilation (use a .cpp suffix)
#endif
No, it's not 'afx.h' - you never compile '*.h' file directly, they are included by '*.cpp' files while compiled.

The default compile order is:
- stdafx.cpp (this includes 'stdafx.h' the first time)
- <all other .cpp files> (all of these usually include 'stdafx.h' too)

So, the output when compiling should be somehow like this:

1> ------ Build started: Project: <Your project's name>, Configuration: Debug Win32 ------
1> stdafx.cpp
1> ...
1> c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(736) : error C2061: syntax error : identifier '_Out_z_cap_'

before that last line (so in '1> ...') maybe further '*.cpp' appear - the last one is that which fails to compile (this even could be 'stdafx.h' - if so I would guess 'stdafx.cpp' is compiled as C instead of C++).

If this doesn't help please post the complete output from the first line up to the first error message you posted above ...

ZOPPO
Avatar of thready

ASKER

>------ Build started: Project: USBHIDCardReaderThread, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(735) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(736) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(736) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(737) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(738) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(738) : error C2143: syntax error : missing ')' before ';'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(772) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(773) : error C2059: syntax error : ')'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(773) : error C2143: syntax error : missing ')' before 'const'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(946) : error C2061: syntax error : identifier '_Out_z_cap_'
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afx.h(947) : error C2059: syntax error : ')'
Ok, so I guess you changed settings for 'stdafx.cpp' to compile as C instead of C++.

You should NOT compile anything as C if you don't really need to ...

BTW: Does your project include any '*.c' files or CPP files which differ from '*.cpp' (i.e. *.c++)? If so maybe VC 2008 automatically compiles them as C instead of C++
Avatar of thready

ASKER

My project only has .cpp files and 1 .def  (which has the following in it):

; USBHIDCardReaderThread.def : Declares the module parameters.

LIBRARY      "USBHIDCardReaderThread.DLL"

EXPORTS
      DllCanUnloadNow     @1 PRIVATE
      DllGetClassObject   @2 PRIVATE
      DllRegisterServer   @3 PRIVATE
      DllUnregisterServer      @4 PRIVATE
The .def file shouldn't matter at all.

Please check if 'stdafx.cpp' is really compiled as C++ (via file's properties as described above) ...
don't think that stdafx.cpp was compiled as C. Then the first errors would be much earlier than line 736.

i assume you have the stdafx.cpp and stdafx.h from vc6. do the following:

create a new dummy project in VS2008 with the wizard which is  most similar to your old project. I. e. if the old one was dialog-based create a dialog-based one. if it was sdi or mdi do the same. Take stdafx.h and stdafx.cpp from the new project and replace the stdafx.h and stdafx.cpp of the current project (save the original files somewhere). try to build. if you were lucky it wil work.
for your information: stdafx.h is a so-called precompiled header which normally includes all winapi, mfc, atl ... then there is stdafx.cpp which contains nothing but include of stdafx.h. when stdafx.cpp was built it creates the precompiled-header file .pch which contains all object code of stdafx.h (you could say it compiled the header). then all other .cpp of project have first include stdafx.h and the compiler instead of compilng winapi and mfc every time again simply takes the .pch and puts it as it is to the object module .obj (machine code).
> don't think that stdafx.cpp was compiled as C. Then the first errors would be much earlier than line 736.
Yes, I agree, you're right. Sorry, dumb idea ...

But from the code I don't see how it could be that these errors occur - 'afx.h' includes 'new.h', 'new.h' includes 'crtdefs.h', 'crtdefs.h' includes 'sal.h' in which '_Out_z_cap_' is defined.


@thready: please check if maybe in your project's properties some wrong directories (i.e. absolute paths to VC 6 include files) are used, i.e. in 'General->Additional include directories' or 'Precompiled headers->Precompiled header file'
my guess is that stdafx.h from vc6 contains some older macros like WIN32_MEAN_AND_CLEAN which could lead to needed header files were not included. or it includes some headers still existing in vc9 but not in the right order. or some needed macros like _WIN32_WINNT were not set at all or set to wrong windows version (i mean to remember that i had to add it for every new project).
Avatar of thready

ASKER

ok - I decided to start from scratch - I created a new MFC DLL project with ATL Support.  I re-added my interface functions and properties and everything compiles with no errors and no warnings.

Now, to prepare for the files I think I need from the DDK, I add the following includes to the additional include directories (without doing anything else)
C:\WinDDK\7600.16385.0\inc\api;C:\WinDDK\7600.16385.0\inc\ddk;C:\WinDDK\7600.16385.0\inc\crt

And this gives me the following errors when I compile:
1>------ Build started: Project: USBHIDCardReaderThread, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_S1max' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_N' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C3861: '_Out_bytecap_post_bytecount_': identifier not found
.................
  Now I add my C++ class which will get called appropriately from the COM class- back to square 1:

1>------ Build started: Project: USBHIDCardReaderThread, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_S1max' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_N' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C3861: '_Out_bytecap_post_bytecount_': identifier not found
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2144: syntax error : 'vo

After adding this class and adding
Avatar of thready

ASKER

oops - please completely ignore my last message - I forgot to delete the rest (because I simplified what I was doing to present it to you guys to show the bare minimum of what causes these errors)
Here's what I should have wrote:
----------------------------------------------
ok - I decided to start from scratch - I created a new MFC DLL project with ATL Support.  I re-added my interface functions and properties and everything compiles with no errors and no warnings.

Now, to prepare for the files I think I need from the DDK, I add the following includes to the additional include directories (without doing anything else)
C:\WinDDK\7600.16385.0\inc\api;C:\WinDDK\7600.16385.0\inc\ddk;C:\WinDDK\7600.16385.0\inc\crt

And this gives me the following errors when I compile:
1>------ Build started: Project: USBHIDCardReaderThread, Configuration: Debug Win32 ------
1>Compiling...
1>stdafx.cpp
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_S1max' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C2065: '_N' : undeclared identifier
1>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\atlalloc.h(227) : error C3861: '_Out_bytecap_post_bytecount_': identifier not found
.................
what is the unknown type before _Out_z_cap_? or is _Out_z_cap_ the unknown type?
Avatar of thready

ASKER

Well, now it's not that same error...  I removed my file that has that error in it, I'm just trying to do something more basic- be able to include the DDK include files needed (without even using them yet)...

As for Out_z_cap - that's in afx.h -->  it looks to me like some sort of MIDL parameter output specifier...
class AFX_NOVTABLE CException : public CObject
{
      // abstract class for dynamic type checking
      DECLARE_DYNAMIC(CException)

public:
// Constructors
      CException();   // sets m_bAutoDelete = TRUE
      explicit CException(BOOL bAutoDelete);   // sets m_bAutoDelete = bAutoDelete

// Operations
      void Delete();  // use to delete exception in 'catch' block

      virtual BOOL GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpszError, _In_ UINT nMaxError,
            _Out_opt_ PUINT pnHelpContext = NULL) const ;
      virtual BOOL GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpszError, _In_ UINT nMaxError,
            _Out_opt_ PUINT pnHelpContext = NULL);
      virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);

// Implementation (setting m_bAutoDelete to FALSE is advanced)
public:
      virtual ~CException() = 0;
      BOOL m_bAutoDelete;
#ifdef _DEBUG
      void PASCAL operator delete(void* pbData);
#if _MSC_VER >= 1200
      void PASCAL operator delete(void* pbData, LPCSTR lpszFileName, int nLine);
#endif
protected:
      BOOL m_bReadyForDelete;
#endif
};
the _Out_z_cap_ most probably is a macro that can generate an additional argument - probably an array - . You could search where it is defined and check where it normally was not included and probably find out why it wasn't included in the current case. alternatively you simply can add _Out_z_cap_(n) to your preprocessor macros what should solve that error.

your ddk-errors: w wouldn't add the ddx include path to additional project includes but to the general include directories (tools - option - projects - vc-directories - include directories). here absolute paths are more appropriate. the problem i see with the ddk is if it contains same header files as the vc. then you get a mix which hardly could ever be built. check the files which gave errors whether they exist more than once.

Hi,

about that errors:

> error C2065: '_S1max' : undeclared identifier
> ...

Maybe you need to change the directory settings in VC 2008 so the DDK-folders 'override' the default VC 2008 directories (so just move them to the top of the list - if they don't exist in the list then add them)

ZOPPO
Avatar of thready

ASKER

ok - I'd like to use the DDK directories for that project and prevent the ones for VC, but how do I set up just this project to do this?  (because I don't want to use the DDK for anything except this project)
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
better get you a ddk fitting to vs2008. i don't think you can mix vc6 ddk with vs2008. also absolute include paths should be put to general include paths. relative paths (relative to project folder like ..\other_project) should be added to additional project includes. never use two include folders where the same include files exists with different version. independent of the order you define them the vc precompiler may use the one or the other. different versions of header files included give heap corruption and crash.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of thready

ASKER

Thanks guys, I now have a problem linking, I might post another question related to this...