unidentified datatype in external header - c++

I am attempting to write a .dll using a library that comes with some demo projects that run with no issues. When I attempt to #include a header, the compiler complains that certain datatypes are not defined. here is a sample of the errors generated
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(82) : error C2061: syntax error : identifier 'LPCWSTR'
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(90) : error C2061: syntax error : identifier 'LPCWSTR'
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(97) : error C2061: syntax error : identifier 'LPCWSTR'
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(107) : error C2061: syntax error : identifier 'LPCWSTR'
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(110) : error C2061: syntax error : identifier 'DWORD'
1>c:\program files (x86)\audiokinetic\wwise v2012.1.4 build 4260\sdk\include\ak\wwise\utilities.h(113) : error C2061: syntax error : identifier 'DWORD'
adding
#include <windows.h>
#include <atlstr.h>
to this external utilities.h file solves the problem, but as its a 3rd party header I don't believe I should be editing it, and considering these other demo projects #include the same header as I am, it seems to suggest that the problem lies elsewhere.
Can anyone think of a reason why this could be happening. The library I'm trying to use is Wwise (a sound engine). Here is a list of .libs im linking
AkSoundEngine.lib
AkMemoryMgr.lib
AkStreamMgr.lib
AkMusicEngine.lib
CommunicationCentral.lib
dxguid.lib
ws2_32.lib
dsound.lib
dinput8.lib
xinput.lib

Typically this is solved by changing the order your headers are included.
Assuming a file called header.h has the following:
LPCWSTR foo;
In you main:
// This is fail.
#include "header.h"
#include <windows.h>
Try:
// Success!
#include <windows.h>
#include "header.h"

Related

#include <Dbghelp.h> doesn't include the header

If you include #include <Dbghelp.h> in, for example, a console C++ application, it will not bring any definitions from the header file and there are more or less similar compiler errors as if this header is not included at all.
Compiler errors looks like:
1>------ Build started: Project: ConsoleDump, Configuration: Debug Win32 ------
1> ConsoleDump.cpp
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2146: syntax error: missing ';' before identifier 'Flags'
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2065: 'Flags': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(23): error C2065: 'MiniDumpWithFullMemory': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(24): error C2065: 'MiniDumpWithFullMemoryInfo': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(25): error C2065: 'MiniDumpWithHandleData': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(26): error C2065: 'MiniDumpWithUnloadedModules': undeclared identifier
1>e:\projects\vs2015 projects\consoledump\consoledump\consoledump.cpp(27): error C2065: 'MiniDumpWithThreadInfo': undeclared identifier
What's going wrong?
You must included <windows.h> before <DbgHelp.h>, and if the project uses "Stdafx.h", it must be included before everything else. The following is the correct order:
#include "stdafx.h"
#include <windows.h>
#include <Dbghelp.h>
Also make sure to link DbgHelp.lib to 'Project settings' > Linker > Input > 'Additional Dependencies'.

defining _WINSOCKAPI_ causes error in visual studio 2012 migration

So I'm trying to update a windows build of a project and encountered this error,
1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h(452): error C2059: syntax error : 'constant'
1>C:\Program Files (x86)\Windows Kits\8.0\Include\shared\ws2def.h(452): error C3805: 'constant': unexpected token, expected either '}' or a ','
I determined that winsock.h must have been included earlier than Winsock2.h which was included in the error'd file so I defined
_WINSOCKAPI_
in the project properties to make sure that didn't happen.
However now I get like 8 other errors from files that include afxsock.h saying "error : MFC requires use of Winsock2.h". So is
_WINSOCKAPI_
preventing afxsock.h from including winsock? Because it seems like I have this circular error and only one set of files can build properly.

error MIDL2003: redefinition when compiling ATL generated idl with windows.h and sql.h included

As part of a requirement, I had to include sql.h and windows.h in an ATL generated idl.
Unfortunately, it keeps on complaining when sql.h is included
1>c:\program files (x86)\windows kits\8.0\include\um\sqltypes.h(125): error MIDL2003: redefinition : SQLSCHAR
1>c:\program files (x86)\windows kits\8.0\include\um\sqltypes.h(131): error MIDL2003: redefinition : SQLUINTEGER
And when windows.h is included it complains
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(347): error MIDL2003: redefinition : INT
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(832): error MIDL2003: redefinition : Int64ShllMod32
1>C:\Program Files (x86)\Windows Kits\8.0\Include\um\winnt.h(832): error MIDL2025: syntax error : expecting ; near "{"
Note I am creating a COM wrapper over ODBC because of which I need to include these files in my generated idl
One way to get around this is to define RC_INVOKED before the header files are included. This will skip the typedef's and #define's which conflict with declarations in MS IDL files.
import "oaidl.idl";
import "ocidl.idl";
#define RC_INVOKED 1
#include "windows.h"
#include "sql.h"

Boost foreach conflicts with Q_FOREACH (Qt) and moc generation?

I have a program edited in Vs 2008 using some libraries such as Qt and Point Cloud Library (PCL).
PCL has a 3rd party library which contains boost.
However, some errors appeared after compiling:
1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/sequenced_index.hpp(926)
: error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/ordered_index.hpp(1399) : error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/hashed_index.hpp(1254) : error C2061: syntax error : identifier 'tag' 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C3083: 'Q_FOREACH': the symbol to the left of a '::' must be a
type 1>C:\Program Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C2039: 'tag' : is not a member of 'boost' 1>C:\Program
Files\PCL
1.5.1\3rdParty\Boost\include\boost/multi_index/random_access_index.hpp(1012)
: error C2061: syntax error : identifier 'tag'
For the first problem, the error location in the source file is:
template<typename SuperMeta,typename TagList>
inline boost::mpl::true_* boost_foreach_is_noncopyable(
boost::multi_index::detail::random_access_index<SuperMeta,TagList>*&,
boost::foreach::tag) // <-------------error here for the first compile error.
{
return 0;
}
I think maybe this indicates that the Q_FOREACH conflicts with the boost foreach.
But I do not know how to solve this problem?
The problem is that Qt defines a foreach macro (#define foreach Q_FOREACH) which conflicts with the boost::foreach namespace.
The easiest ways to solve it is to either include Boost before Qt or simply undefine the Qt's macro before including the boost's header file. I prefer the second since it won't need extra documentation (// remember to include Boost before Qt), and it is easier to manage in nested header files and if you use precompiled headers.
#undef foreach
#include <boost/foreach.hpp>
This option is less invasive than disabling Qt's keywords (compilation flag -DQT_NO_KEYWORDS) and can be applied only in the affected files if wanted. It won't affect the use of Q_FOREACH (obviously if you use the Qt's foreach it will fail). It also works independently that Qt is included before or after <boost/foreach.hpp>.
Setting compiler flag -DQT_NO_KEYWORDS, disables the clash between boost and qt!
But then you need to replace the qt keywords in your code like slots, signals, emit ..., see this post.
(I got this message when introducing boost::multi_index container in my project.)
(For qmake projects CONFIG += no_keywords does this.)
(For cmake project add_definitions(-DQT_NO_KEYWORDS) does this.)

Why do I get errors when I #include curl.h?

I'm trying to get libcurl to work with my C++ project.
I've added libcurl to my project.
I've also added the header files, preprocessor and linker configuration.
When adding #include to my project I get a lot of winnt.h errors:
c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2988: unrecognizable template declaration/definition
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2059: syntax error : '('
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\winnt.h(1084): error C2090: function returns array
...
What is the reason to this problem?
Thanks.