C++ TlHelp32.h not working? - c++

I've included the TlHelp32.h header properly though I keep getting the message:
"Error: identifier "CreateToolhelp32Snapshot" is undefined"
when attempting to use CreateToolhelp32Snapshot. When I used the "peek definition" feature in VS I found that there are errors within this header where in certain areas it says:
"Error expected a ';'"
Any ideas how to fix this?
#include "stdafx.h"
#include <TlHelp32.h>
#include <Windows.h>
#include <iostream>
using namespace std;
class Functions{
public:
void playerHealthPrinter(){
HANDLE hProcess;
DWORD dwPID, dwProtection, dwCaveAddress;
BOOL bPOn, bIOn, bProt;
HANDLE hPID = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

Never include Win32 headers before <windows.h>. The following should work, instead:
#include <Windows.h>
#include <TlHelp32.h> // <-- include *after* windows.h
If it still doesn't work then please post an MCVE including the relevant headers and version of VS.

Related

CreateWindow class method throwing expected a type specifier - windows.h

Take the following code:
# pragma once
// Windows specific files
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include "IOS.h"
namespace PlatformGameEngine
{
class OSWindows : public IOS
{
public:
virtual void CreateWindow( const WindowProperties windowProperties ) override;
};
}
If i remove the #include <windows.h> the code compiles fine. If i keep it in, I get an error pop up under the virtual void CreateWindow part...
expected a type specifier
What's going on here? How do i solve it?
CreateWindow is an evil macro. If you include the header that defines it, you can't use the name for any other purpose.
Either stop supporting Microsoft or, if you really must do that, choose a different name for your function. Or maybe add #undef CreateWindow and hope for the best.

'SHGFP_TYPE_CURRENT' was not declared in this scope

I am migrating a huge project from Qt 4.x to 5, (in fact I have asked for help several times here, I couldnt be more grateful for your help).
I am getting the next error:
..\marssies\userlayerswidget.cpp: In member function 'void
LayersModel::importFromOld()':
..\marssies\userlayerswidget.cpp:1736:60: error: 'SHGFP_TYPE_CURRENT'
was not declared in this scope
It doesnt make too much sense, as I have the correct header included, here are all the includes:
#include "userlayerswidget.h"
#include "appcommon.h"
#include "messagebox.h"
#include "polyline.h"
#include "painterbar.h"
#include "rectangle.h"
#include "polygon.h"
#include "label.h"
#include "line.h"
#include "point.h"
#include "encsymbol.h"
#include "touchswibz.h"
#include "mapmodulelist.h"
#include "offlinelayersaver.h"
#include "circle.h"
#include <QMenu>
#include <QDir>
#include <QDesktopServices>
#include <QtDebug>
#ifdef _WIN32
#include <Shlobj.h>
#endif
And here is the piece of code that makes use of SHGFP_TYPE_CURRENT:
void LayersModel::importFromOld() {
TCHAR appPath[MAX_PATH];
if (!(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, appPath))) {
//code
}
I have researched and everything is correct according to http://msdn.microsoft.com/en-us/library/bb762181%28VS.85%29.aspx
I tried to find other people with the same problem but either the context was different or the question wasnt answered.
Thankyou.
In ShlObj.h is SHFGP_TYPE_CURRENT defined like this:
#if (_WIN32_IE >= 0x0500)
typedef enum {
SHGFP_TYPE_CURRENT = 0,
SHGFP_TYPE_DEFAULT = 1,
} SHGFP_TYPE;
#endif
So one can do this:
#define _WIN32_IE 0x0500
#include <ShlObj.h>
Or another way is to directly use value 0 or 1 as parameter to SHGetFolderPath.
Doing more research I found an answer that was to replace SHGFP_TYPE_CURRENT with a literal 0, I did it and it compiled, but I'm not sure if it will be the same (I haven't written this program, I'm just migrating it). So if anybody could give some insight it would be nice.
Source: http://webcache.googleusercontent.com/search?q=cache:http://www.dreamincode.net/forums/topic/200660-undeclared-variable/

Compile errors when attempting to link <boost\property_tree\json_parser.hpp>

I have the following "includes" file in my project.
#pragma once
//glm
#include <glm\glm.hpp>
#include <glm\ext.hpp>
#include <glm\gtc\matrix_transform.hpp>
//glew
#include "GL\glew.h"
//glfw
#define GLFW_DLL
#include "GLFW\glfw3.h"
//libpng
#include <png.h>
//std
#include <stdio.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <list>
#include <memory>
#include <iostream>
#include <fstream>
#include <assert.h>
//boost
#include <boost\filesystem.hpp>
#include <boost\property_tree\json_parser.hpp> /* problem */
//mandala
#include "types.h"
#include "type_traits.h"
#include "hash.h"
#include "macros.h"
When I include <boost\property_tree\json_parser.hpp>, I get many errors indicating that I'm redefining APIENTRY such as this one:
1>c:\program files (x86)\windows kits\8.0\include\shared\minwindef.h(130): warning C4005: 'APIENTRY' : macro redefinition
I'm perplexed as to why this is happening. I've tried to suppress the minwindef.h file from being processed by putting #define _MINWINDEF_ before the include statement but to no avail. Has anyone else encountered this or have any idea how I can properly include this boost library?
NOTE
Since youd did neither update your question to reflect the changes to the includes you made, nor provide the whole warning message, I can only guess:
You still have glfw.h included before the boost lib that includes the WinAPI header. Because when I just google for "APIENTRY redefinition", I get this SO question as first result, including the answer: Put the WinAPI header (or the boost header includign them) before the glfw.h include.
You may want to include also ptree.
#include <boost/property_tree/ptree.hpp>

includes and the order at which they are called in C++, windows

I'm a little confused at why this is and i'm sure it's a basic thing I should know if i'm programming in C++ but here is the question:
I have a "Windows.cpp" and at the top it has includes of
#include <windows.h>
#include "Game.h"
#include "Mouse.h"
#include "Screen.h"
...
In my Screen.h I have the following which obviously requires information from windows.h because of the use of DWORD:
#pragma once
#include <windows.h>
class ScreenServer;
class ScreenClient
{
public:
ScreenClient( const ScreenServer &server );
DWORD GetScreenHeight();
DWORD GetScreenWidth();
...
The question is, why do I have to #include windows.h within Screen.h, when my "Windows.cpp" already has included it before "Screen.h" is included?
Short answer:
Because some other file that doesn't #include <windows.h> might include Screen.h.
A bit longer:
In general, you should always include the headers you need, where you need them, and not rely on them being included somewhere else. Use forward declarations where possible, but if you need a full type, include the header.

windows.h already included afxv_w32.h - CString

Am trying to include CString in my cpp file but am getting this error if i include afxinet.h
"windows.h already included afxv_w32.h"
These are my header files :
#include stdafx.h
#include shlwapi.h
#include Tlhelp32.h
#include hooks.h
#include stdio.h
#include common1.h
#include SafeLogger.h
#include io.h
#include tinyxml.h
#include winsock.h>
#pragma comment(lib, "Ws2_32.lib")
#include afxinet.h
I havent included the gaurds in stack to display here.
how to solve this issue and get to include CString in my file
Why are you adding afxinet.h if you want CString?
You should include atlstr.h to get CString - particularly if your project isn't MFC based.
Use /showIncludes option in C++ settings (Under Advanced). This will show how headers are being included (in tree-format). As another suggestion, you should include only files that are needed.
By including < afx.h >, you should be able to use CString class in cpp file.
#include <afx.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
CString str("Santosh");
wcout << LPCTSTR(str) << endl;
return 0;
}
Additionally, you will need to define _AFXDLL preprocessor