Having difficulty resolving a circular dependency problem when including a windows header - c++

I am new to using COM interfaces, and there's one method in particular that I would like to call in my cppWinRT app:
ICompositionGraphicsDeviceInterop::GetRenderingDevice()
The first problem I am having is what appears to be a circular dependency problem when I try to add #include <windows.ui.composition.interop.h> into my pch.h, which currently looks like this:
#pragma once
#include <windows.h>
#include <unknwn.h>
#include <restrictederrorinfo.h>
#include <hstring.h>
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.ApplicationModel.Activation.h"
#include "winrt/Windows.UI.Xaml.h"
#include "winrt/Windows.UI.Xaml.Controls.h"
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
#include "winrt/Windows.UI.Xaml.Data.h"
#include "winrt/Windows.UI.Xaml.Markup.h"
#include "winrt/Windows.UI.Xaml.Navigation.h"
#include <winrt/Windows.UI.ViewManagement.h>
#include "winrt/Windows.ApplicationModel.Core.h"
#include "winrt/Windows.UI.Core.h"
#include <windows.ui.composition.interop.h>
I get the following compiler error:
c:\program files (x86)\windows kits\10\include\10.0.17744.0\winrt\windows.ui.composition.interop.h(100): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I tried to figure out which type is causing the problem, but I can't figure out which one at line 100 of windows.ui.composition.interop.h is problematic.
How can I solve this?

There was a macro at line 100, which required me to include "combaseapi.h".

Related

Errors when including intrin.h?

I'm trying to build my project, which uses things like __cpuid and __cpuidex, so I need intrin.h. When I try to include it and build my project, I get two errors. They are:
`tagMENUBARINFO::fUnused`: type of bit field too small for number of bits
in winuser.h, and in minwindef.h I get the error
`BOOL`: redefinition; different basic types
My includes:
#include <Windows.h>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <algorithm>
#include <intrin.h>
I need all of these includes, so removing some isn't really an option.
I'm using Visual Studio 2019 as my compiler, my Windows SDK Version is 10.0, and the C++ language standard is ISO C++14 Standard.

After defining a function in another file, visual studio does not recognize the function

I'm creating windows console app that has many pages (split in files). I'm facing a problem when executing the program and Visual Studio throws 'startpage' identifier not found error (startpage is the function and the file name is startpage.h)
I've tried using:
external int startpage(); and
int startpage();.
I've tried changing only the function name too (so the file and function don't use the same name).
I have no idea why this is happening. Other files with different functions are working. The file "startpage.h" uses two functions defined in other files, and those are not throwing any errors.
#include "include/startpage.h"
#include <iostream>
#include <conio.h>
#include "include/concol.h"
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
startpage();
}
```
Here is the error:
Error code: C3861: 'startpage' identifier not found
Move #include "pch.h" to the top. The compiler ignores everything above the inclusion of precompiled header. – Igor Tandetnik
This worked!
Thank you so much guys!

How to properly include headers and use STL vector in c++ app?

I decided to try STL and use a vector instead of a custom made growable array class. The problem is that I can't get anything to compile. If I do something like this:
#include "stdafx.h"
#include <vector>
std::vector<PITEMID_CHILD> APIDL;
I get a bunch of messages similar to this:
1>c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\include\cstdint(23): error C2039: 'int_least8_t': is not a member of '`global namespace''
If I change to this:
#include <vector>
#include "stdafx.h"
std::vector<PITEMID_CHILD> APIDL;
I get this:
1>x:\win32testing\vectortest\vectortest.cpp(4): error C2039: 'vector': is not a member of 'std'
Inside of stdafx.h is this:
#pragma once
#include <windows.h>
#include "targetver.h"
// C RunTime Header Files
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <shlobj.h>
#include <exdisp.h>
#include <shellapi.h>
#include <shlwapi.h>
#include <atlbase.h>
#include <atlalloc.h>
#include <CommonControls.h>
// reference additional headers your program requires here
#include <CommCtrl.h>
Any idea what is going on?
From wikipedia documentation:
Visual C++ will not compile anything before the #include "stdafx.h" in the source file, unless the compile option /Yu'stdafx.h' is unchecked (by default); it assumes all code in the source up to and including that line is already compiled.
The best solution is to get rid of precompiled headers.
And for your C2039 error, it doesn't seem to be a result of line std::vector<PITEMID_CHILD> APIDL;. int_least8_t is a type defined in cstdint (stdint.h). It seems you haven't included this header file in your project.

#include "glm/ext.hpp" makes the compiler report a __declspec(align('16')) won't be aligned

I get the compiler error __declspec(align('16')) won't be aligned.
When I click the error, Visual Studio sends me to GLM_IMPLEMENT_SCAL_MULT(vec4), which is on the scalar_multiplication.hpp file.
What is the cause for this compiler error? How can I fix it?
Note: Could it be some kind of conflict with the includes? I have several includes in a header file. The commented one is the one that gives the error.
// OpenGL Math library
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
//#include "glm/ext.hpp" // For printing matrices
#include <SFML/Graphics.hpp>
#include <GL/glew.h>

Syntax errors in C++ include file

I'm writing a game in c++ in microsoft visual studio 2010, yesterday I wrote a pong game and everything was fine but now the compiler telling me that there is a lot of errors for example:
1>w:\c++\planet escape\planet escape\room.h(25): error C2061: syntax error : identifier 'WorldMap'
And here is the Room.h file:
#pragma once
#include <allegro5/allegro.h>
#include <vector>
#include "Entity.h"
#include "WorldMap.h"
#include "Link.h"
#define ROOM_W 20
#define ROOM_H 20
class Room{
private:...
public:...
};
When in code there is no mistakes and it sees all the classes fine.
So what can cause such mistake?
EDIT:
here is the WorldMap.h
#pragma once
#include <allegro5/allegro.h>
#include "Room.h"
#include "Player.h"
#define WORLD_W 10
#define WORLD_H 10
class WorldMap{
private:...
public:...
};
If when I'm runing it he cant see it then why he see it when coding?
You have circular includes. Suppose you are compiling a file that has a #include "WorldMap.h" as the first applicable #include statement. The file WorldMap.h has that #include "Room.h" that is going to cause a lot of trouble. The problems start in earnest in Room.h at the #include "WorldMap.h" statement. That #include has no effect thanks to the #pragma once in WorldMap.h. When the compiler gets to the point of processing the main body of Room.h, the class WorldMap is neither defined nor declared.
Addendum
The solution is to get rid of those extraneous #include statements. The file WorldMap.h does not need to #include either of Room.h or Player.h. It instead needs to make forward declarations of the classes Room and Player. Similarly, you don't need all those #include statements in Room.h either.
It is in general a good idea to use forward declarations of types in your headers instead of including the file that defines the types. If the code in the header does not need to know details of the type in question, just use a forward declaration. Do not #include the header that defines the type.