For some reason I am totally lost on this issues and been looking for an hour without any help.
in dev c++ I keep getting this error and it points to the line in [strong]bold[/strong]:
"18 H:\Projects\Classic Lockdown\main.cpp expected constructor, destructor, or type conversion before '(' token"
#define INFO_BUFFER_SIZE 32767
#include "iostream"
using namespace std;
#include <windows.h>
#include <gdiplus.h>
//#include <GdiPlusGetEncoderClsid.h>
#include <stdio.h>
HINSTANCE G_HINS_hInstance = 0;
#include "sstream"
#include "..\PWS_DEV\PWS_DEV.h"
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
//GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput,NULL);
Bitmap *gdiBitmap = 0;
#include "procedures.h"
why is it doing this?
I also wanted to see if I tried this instead
...
Gdiplus::GdiplusStartup = "";
...
and then I get this error instead:
"18 H:\Projects\Classic Lockdown\main.cpp expected constructor, destructor, or type conversion before '=' token"
not matter what I used with GdiplusStartup it just keeps saying that over and over. Its like it doesn't want anything to do with GdiplusStartup
I am very stuck on this. Can some one please help me out with this?
if you need any more info about this or the project i'm working on, please let me know.
Thank you
A couple of things jump out:
You have &m_gdiplusToken instead of &gdiplusToken (variable names don't match).
I assume the call to GdiplusStartup is in a function, right?
If I rearrange like this, it compiles fine with: cl.exe /EHsc so_test.cpp
Note I commented out headers I don't have. If it's still failing for you, you probalby have bad code in a header or you're not showing us everything.
#define INFO_BUFFER_SIZE 32767
#include "iostream"
using namespace std;
#include <windows.h>
#include <gdiplus.h>
//#include <GdiPlusGetEncoderClsid.h>
#include <stdio.h>
HINSTANCE G_HINS_hInstance = 0;
#include "sstream"
// #include "..\PWS_DEV\PWS_DEV.h"
#pragma comment( lib, "gdiplus" )
using namespace Gdiplus;
//#include "procedures.h"
int main()
{
//GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput,NULL);
Bitmap *gdiBitmap = 0;
return 0;
}
Related
Here's the code:
AnsiString path = "BrowserBot.exe";
ShellExecute(0, TEXT("open"), path.c_str(), TEXT("-parametr"), 0, SW_SHOW);
Writes an error that the AnsiString identifier is not defined. I don't know what the problem is.
All connected libraries:
#include <iostream>
#include <conio.h>
#include <Windows.h>
#include <fstream>
#include <sstream>
AnsiString is a string class that is specific to the C++Builder compiler. If you are using that compiler, make sure you are compiling your project with C++Builder's VCL (Visual Component Library) or FMX (FireMonkey) framework enabled, and that you have a corresponding #include <vcl.h> or #include <fmx.h> statement in your C++ code.
Otherwise, if you are using any other compiler, you should use the standard C++ std::string class instead (which can also be used in C++Builder), eg:
#include <string>
std::string path = "BrowserBot.exe";
ShellExecuteA(0, "open", path.c_str(), "-parametr", 0, SW_SHOW);
Disclaimer: C++ Redefinition Header Files (winsock2.h) doesnt solved my problem
In this project, im trying to take a screenshot and then compressing it with libjpeg-turbo. The problem is that i get errors like
"sockaddr": "struct" Type redefinition
and
"nothl": Redefinition
ScreenWorker.h:
#pragma once
#ifndef SCREENWORKER_H
#define SCREENWORKER_H
#include <string>
#include <vector>
#include <thread>
#include <turbojpeg.h>
#include <Windows.h>
#include "..\API\NetClient.h"
class ScreenWorker {
private:
NetClient* client;
public:
int delay = 30;
ScreenWorker(NetClient* client);
HBITMAP GetScreenBmp(HDC hdc);
void Update();
};
#endif
ScreenWorker.cpp:
#include "ScreenWorker.h"
ScreenWorker::ScreenWorker(NetClient* client) {
this->client = client;
Update();
}
HBITMAP ScreenWorker::GetScreenBmp(HDC hdc) {...}
void ScreenWorker::Update() {...}
The main.cpp (DLL-Entry):
#pragma once
#include "..\..\Base\API\API\GladOSClient.h"
#include "ScreenWorker.h"
using namespace std;
BOOL WINAPI DllMain(HINSTANCE Instance, DWORD Reason, LPVOID Reserved) {
return true;
}
NetClient.h (only Header part):
#pragma once
#ifndef NETCLIENT_H
#define NETCLIENT_H
#define _WINSOCKAPI_
#include <Windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <vector>
#include <list>
#include <mutex>
#include <map>
#include <string>
#pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib")
#include "Utils.h"
#include "PacketHandler.h"
#include "Packet.h"
...
#endif
As you can see, i'm using header-guards everywhere, but nevertheless i get those errors. Seems like there is a problem with the including of "Windows.h"?
Thanks in advance!
Edit
I guess the problem has something to do with the way libjpegturbo handles the including of "Windows.h". Currently i have no real way of solving this issue. Maybe im trying exporting the function i need in a seperated DLL... hopefully this will solve it.
Classic issue.
Just remove this line from NetClient.h
#include <Windows.h>
The inclusion of <Winsock2.h> will pull in <windows.h> for you and correct all those redefine issues.
Intro
First of all, I would like to say that I have read through the previous answers for this type of question, including this excellently written one.
However, I do not understand enough about C++ to be able to use the more "advanced" fixes.
I have ensured that the right type of console has been selected (Console (/SUBSYSTEM:CONSOLE) for those interested), and have the required imports with the possible exception of an IDL mentioned somewhere (that falls into the lack of understanding category).
If this is a duplicate, I would be more than happy to use the post I duplicated, but I have not been able to find anything that can help someone of my skill level.
Technical Information
IDE: Visual Studio
Platform: Windows
Code
headers.h
#pragma once
#include <stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <Shobjidl.h>
#include <time.h>
#include <stdlib.h>
#include <tchar.h>
main.cpp
#include "headers.h"
using namespace std;
int main() {
string x = "C://Users/student/Desktop/i-should-buy-a-boat.jpg";
x.c_str();
wstring tempx = std::wstring(x.begin(), x.end());
LPCWSTR sw = tempx.c_str();
HRESULT SetWallpaper(
LPCWSTR monitorID,
LPCWSTR wallpaper
);
SetWallpaper(NULL, sw);
}
SetWallpaper() is not a standalone function exported by the Win32 API. It is a method of the IDesktopWallpaper interface (see here).
So you need to use code that is more like this instead:
#include "headers.h"
int main()
{
std::wstring x = L"C:\\Users\\student\\Desktop\\i-should-buy-a-boat.jpg";
CoInitialize(NULL);
IDesktopWallpaper *p;
if (SUCCEEDED(CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&p)))
{
p->SetWallpaper(NULL, x.c_str());
p->Release();
}
CoUninitialize();
return 0;
}
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.
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/