Inclusion of dshow.h results in definition errors - c++

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

Related

error C2732: linkage specification contradicts earlier specification for 'log'

I wrote some functions,and complied it to a dll module .In my header file as followed:
#ifndef GET_DATAFEED_FORKDB_H
#define GET_DATAFEED_FORKDB_H
#include "..\include\stdafx.h"
#include <windows.h>
#include "..\include\TDFAPI.h"
#include "..\include\TDFAPIStruct.h"
#include "..\include\PathHelper.h"
#include "..\include\ConfigSettings.h"
// some helper functions
// ....
extern "C" void openConnect();
extern "C" void closeConnect();
#endif
However,when I used Visual Studio 2013 Professional to compile it, i got some errors:
F:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(501) :
error C2732: linkage specification contradicts earlier specification for 'log'
F:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\math.h(501) :
see declaration of 'log'
F:\Program Files (x86)\Microsoft Visual Studio12.0\VC\INCLUDE\xtgmath.h(104)
:error C2732: linkage specification
contradicts earlier specification for 'log'
F:\Program Files (x86)\Microsoft Visual Studio12.0\VC\INCLUDE\xtgmath.h(104)
: see declaration of 'log'
F:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\INCLUDE\xlocale(337)
: warning C4530: C++ exception handler used, but unwind semantics are not
enabled. Specify /EHsc
I have not use math method. so I tried to use this method to solve it, but it did not work. The included head files can't not modified, I also tried use this method:
extern "C" {
#include "..\include\TDFAPI.h"
#include "..\include\TDFAPIStruct.h"
#include "..\include\k.h"
#include "..\include\PathHelper.h"
#include "..\include\ConfigSettings.h"
}
,what's worse, it occurred more errors.
I just come across the same problem as you. I have encountered the same problem as you. The #include "k.h" must be put after including any std headers.

Fix macro redefinition in C++

Since intsafe.h and stdint.h both define INT8_MIN. Thus VS2010 generate a warning that says :
1>C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\stdint.h(72): warning C4005: 'INT8_MIN' : macro redefinition
1> C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\intsafe.h(144) : see previous definition of 'INT8_MIN'
Is there a way to fix that warning in VS2010.
Apparently it's a bug in VS2010. You can avoid it in general but in MFC applications it's basically impossible to ever include stdint.h in any of your other code without hitting it.
I just did this at the top of the file that was complaining:
#pragma warning (push)
#pragma warning (disable : 4005)
#include <intsafe.h>
#include <stdint.h>
#pragma warning (pop)
It gets those headers 'out of the way' so to speak and lets you get on with your day.
In order simply to make the message go away, you can add the line
#pragma warning (disable : 4005)
before your first #include statement
But that doesn't mean you shouldn't heed the warning. See if you can do without one of the two header files, and if not, be very certain of which definition your program is using.

fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h> [duplicate]

This question already has answers here:
Migrating a big project in MFC from Visual C++ 6.0 to Visual Studio 2005
(3 answers)
Closed 2 years ago.
I have a Visual Studio 6.0 project that uses SQL Compact Server.
I'm trying to update the solution to use on Visual Studio 2012, but i have the following error:
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
My stdafx.h includes winsock2.h, who have this:
#ifndef _INC_WINDOWS
#include <windows.h>
#endif /* _INC_WINDOWS */
There is a way to supress the error? How do I proceed? When I remove the windows.h of the files that include it indirectly, I got error C2011: 'IRowsetBookmark' : 'struct' type redefinition
I already saw other questions here about this error, but none of suggestions works for me.
- update:
I solve the error C2011: 'IRowsetBookmark' : 'struct' type redefinition adding the following lines in the top of my stdafx.h:
#if !defined(__IRowsetBookmark_INTERFACE_DEFINED__)
#define __IRowsetBookmark_INTERFACE_DEFINED__
#endif
#if !defined(__IRowsetBookmark_FWD_DEFINED__)
#define __IRowsetBookmark_FWD_DEFINED__
#endif
But i got error C2143: syntax error : missing ',' before '<'
On those line:
class CArrayRowset :
public CVirtualBuffer<T>,
public TRowset
{
Is it possible that adding that lines on my stdfx.h i messed up some class declaration?
try define _INC_WINDOWS before including winsock2.h to void including win.h

Error after created new c++ console application

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.

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.