Error after created new c++ console application - c++

When I create new c++ console application (with MFC checkbox checked) in VS2010 I have a lot of errors during compilation connected with prsht.h, zmouse.h, commctrl.h.
I did not change anything in this file so I have not idea what is wrong. What are this files and how I can compile program without errors?
Few of the many errors (113)
Error 13 error C1903: unable to recover from previous error(s); stopping compilation c:\program files (x86)\microsoft sdks\windows\v7.0a\include\prsht.h 97 1 qwert
Error 10 error C2065: 'CALLBACK' : undeclared identifier c:\program files (x86)\microsoft sdks\windows\v7.0a\include\prsht.h 97 1 qwert
19 IntelliSense: expected a ';' c:\program files (x86)\microsoft sdks\windows\v7.0a\include\commctrl.h 165 21
Error 2 error C2433: 'HWND' : 'inline' not permitted on data declarations c:\program files (x86)\microsoft sdks\windows\v7.0a\include\zmouse.h 141 1 qwert

You can try including the below in stdafx.h file before the #include "targetver.h" statement
#include "Winsock2.h"
#include "Windows.h"
#include "targetver.h"

These errors happened, because compiler treats symbols CALLBACK, HWND, etc. as new, it does not know them.
These symbols are defined in windows.h header file.
So the diagnosis is: windows.h was not included.
This can happen because of ruined SDK files, so you need to reinstall your SDK.
On my computer the header files are included in the following chain:
stdafx.h - afxwin.h - afx.h - afxver_.h - afxv_w32.h - windows.h, zmouse.h, commctrl.h
You can not include windows.h explicitly (as it was suggested before), because afxv_w32.h file has the following lines at the beginning:
#ifdef _WINDOWS_
#error WINDOWS.H already included. MFC apps must not #include <windows.h>
#endif
You can take a look at this: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/fff0ebaa-5153-40b9-89cf-cb9661abb2a4/

You may not cancelled the define code generated by VS:
(in framework.h)
#pragma once
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN
This define command told complier not include some specific headers like Windows. You may forgot to check the MFC support when creating the project.
After comment the #define, it may help.

Related

How can I fix SFML errors in VS 2019 on windows?

I followed a video on LinkedIn to setup SFML, but when I tried compiling the code get several errors, some of which are:
C2065 'Fullscreen': undeclared identifier
C3861 'RenderWindow':identifier not found
C2871 'sf': a namespace with this name does not exist
C2653 'Style':is not a class or namespace name
C2065 'VideoMode':undeclared identifier
C3861 'vm' :identifier not found
C2065 'vm' :undeclared identifier
C26444 Don't try to declare a local variable with no name(es.84)
C2146 syntax error:missing ';' before identifier 'vm'
Assuming (from its name) that "pch.h" generates and/or uses the precompiled header for your build, then that has to be the very first header included in any source file. Otherwise, anything 'gleaned' from headers included before it will be lost, as the compiler only looks in that precompiled header and files included afterwards.
So, just rearrange your top three lines as follows:
#include "pch.h" // MUST be the first header included!
#include <iostream>
#include <SFML/Graphics.hpp>
For an interesting (and informative) discussion about precompiled headers in Visual Studio, see this Stack Overflow question, and the answers there: Precompiled Headers.

Compiling Audacity with VisualStudio 2015 and C++ produces multiple C1189 & C4005 errors

I am using Visualstudio 2015. On Windows 10.I am trying to specifically use the latest VS and SDKs, I do not want to back track to VS2013.
I have gone through the entire code base of Audacity, and changed the instances of
#define snprintf _snprintf
to
#if _MSC_VER < 1900
#define snprintf _snprintf
#endif
However, on rebuilding - I'm still getting these errors.
22>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1925): warning C4005: 'snprintf': macro redefinition
22> C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1925): note: command-line arguments: see previous definition of 'snprintf'
22>C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\stdio.h(1927): fatal error C1189: #error: Macro definition of snprintf conflicts with Standard Library function declaration
I can not see how to get around this? Where is it colliding and thus producing the fatal error.
There are 24 Solutions in the build, and all but three of them build. Theo nes that don't build so far are:
libnyquist
libsndfile
lv2

Header for CStdioFile , if I am already including windows.h

Which header shall i use for CStdioFile?
The relevant doc is here
when I try including afx.h , i get following error( window.h is included before afx.h because of some other function):
Error 1 error C1189: #error : WINDOWS.H already included. MFC apps must not #include C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\atlmfc\include\afxv_w32.h
I wan to remain in native C++ world.
I am using visual studio 2013
If there is a basic setting in project properties that is relevant here, please let me know.

c++ boost compilation catastrophe

I'm writing a DLL plugin for a windows application,
after adding the following includes:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
I get a wonderful compilation error:
Error 3 error C2143: syntax error : missing ';' before '__cdecl' c:\program files (x86)\microsoft visual studio 9.0\vc\include\locale.h 111 LeverateMetaTraderServerAPI
Help?
I'm no authority on C++, but this sort of thing happens when you miss a ; off the end of your class definition.
someone who isn't really smart added this :
#define __declspec(dllexport) __stdcall APIENTRY
to one of the API .h files your including
This error is (with high probability) not caused by Boost. It's probably either the result of a missing semicolon somewhere else in your code or triggered by a missing header include leaving some macro undefined.

Inclusion of dshow.h results in definition errors

I am trying to do a few things using DirectShow for audio playback. I have a header file, at the top is:
#pragma once
#include <dshow.h>
#pragma comment(lib, "strmiids.lib")
and then it goes on to define a class.
When including dshow.h I get the following complilation errors:
C:\Program Files\Microsoft SDKs\Windows\v7.0\include\ddraw.h(703) : error C2011: '_DDPIXELFORMAT' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v7.0\include\ksmedia.h(5749) : see declaration of '_DDPIXELFORMAT'
C:\Program Files\Microsoft SDKs\Windows\v7.0\include\ddraw.h(2249) : error C2079: '_DDSURFACEDESC::ddpfPixelFormat' uses undefined struct '_DDPIXELFORMAT'
C:\Program Files\Microsoft SDKs\Windows\v7.0\include\ddraw.h(2292) : error C2079: '_DDSURFACEDESC2::ddpfPixelFormat' uses undefined struct '_DDPIXELFORMAT'
C:\Program Files\Microsoft SDKs\Windows\v7.0\include\strmif.h(12918) : error C2011: 'tagTIMECODE_SAMPLE' : 'struct' type redefinition
c:\program files\microsoft sdks\windows\v7.0\include\ksmedia.h(5274) : see declaration of 'tagTIMECODE_SAMPLE'
I can't figure out what would cause these errors in this case. The header file is part of an MFC project if that makes any difference. Any advice?
Fixed this by changing the order of the #include definitions. I moved the header file that the above code was defined in to the top and it works ok now. Must have been a clash with some code in another file, possibly some directSound related stuff.
I have faced this SDK integration error a couple times, most recently when integrating a win32 console app with a library that uses Windows CoreAudio and the error occurred with a stdafx.h:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
#define _WIN32_WINNT 0x0502 // Change this to the appropriate value to target other versions of Windows.
#endif
#include <stdio.h>
#include <tchar.h>
// TODO: reference additional headers your program requires here
#include <afx.h>
#include <afxwin.h>
Then to resolve the error, I added the following below the current includes:
#include <winioctl.h>
#if (MSC_VER < 1400)
#include <strmif.h>
#endif
Hopefully this will help someone in the future facing this issue.
EB