Like in the title.
I'm a not very experienced with classes and I have hard time with calling the function EnableStatic() from Win32_NetworkAdapterConfiguration class in C++. So how to do it?
I would really appreciate an example or simple program with it!
Additional Info:
•I've tried use this part of calling code:
#define _WIN32_DCOM
#include <iostream>
#include <winsock.h>
#include <string>
#include <stdint.h>
#include <comdef.h>
#include <Wbemidl.h>
int maint()
{
UINT ipaddr = inet_addr("155.34.22.0");
UINT subnet = inet_addr("255.255.255.0");
Win32_NetworkAdapterConfiguration Adapter;
Adapter.EnableStatic(ipaddr,subnet);
system("pause");
}
•The method's website:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa390383(v=vs.85).aspx
If anyone interested I'm inviting for a C++ project on GitHub
Related
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.
I'm trying to use SRWLock with C++ project Visual Studio 2012 (Windows 7) targeting 32-bit Windows only and SRWLock is better then CriticalSections in my case.
As i've searched, i should include WinBase.h and use std namespace. But SRWLock is still undefined. Couldn't find anything useful on Google. What i'm missing? I appreciate any clues.
Code:
#include <cstdlib>
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <windows.h>
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <conio.h>
#include <WinBase.h>
using namespace std;
SRWLock gLock; // here is the problem
Where was a mistype: Should be SRWLOCK instead of SRWLock.
And you need
#include <windows.h>
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 been creating codes using C++ STL. And I want to use "queue".
So, I wrote the codes like below.
But, I encountered "queue is not a template" error.
As you can see, I wrote headers related with queue (iostream, queue) in "Common.h" file and wrote include "Common.h" in "DataQueue.h" file. But, VS2013 IDE tool said that 'queue m_deQueue' is error because queue is not a template. I don't know why.. this error occured. Any help is appreciated!
//[Common.h]
#ifndef _COMMON_
#define _COMMON_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
//thread related headers
#include <Windows.h>
#include <process.h>
//socket related headers
#include <winsock.h>
#include <iostream>
#include <queue>
#include <deque>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#endif
//[DataQueue.h]
#ifndef _QUEUE_
#define _QUEUE_
#include "SocketStruct.h"
#include "Common.h"
class CDataQueue{
private:
static CDataQueue* m_cQueue;
// deque <ST_MONITORING_RESULT> m_deQueue;
queue <ST_MONITORING_RESULT> m_deQueue;
CRITICAL_SECTION m_stCriticalSection;
CDataQueue();
~CDataQueue();
public:
static CDataQueue* getDataQueue(){
if (m_cQueue == NULL){
m_cQueue = new CDataQueue();
}
return m_cQueue;
}
deque <ST_MONITORING_RESULT> getQueue();
void pushDataToQueue(ST_MONITORING_RESULT data);
ST_MONITORING_RESULT popDataFromQueue();
};
#endif
//[DataQueue.cpp]
#include "DataQueue.h"
CDataQueue* CDataQueue::m_cQueue = NULL;
CDataQueue::CDataQueue(){
::InitializeCriticalSection(&m_stCriticalSection);
// m_mutex = PTHREAD_MUTEX_INITIALIZER;
}
CDataQueue::~CDataQueue(){
::DeleteCriticalSection(&m_stCriticalSection);
}
::deque <ST_MONITORING_RESULT> CDataQueue::getQueue(){
return m_deQueue;
}
void CDataQueue::pushDataToQueue(ST_MONITORING_RESULT data){
::EnterCriticalSection(&m_stCriticalSection);
m_deQueue.push_back(data);
::LeaveCriticalSection(&m_stCriticalSection);
}
ST_MONITORING_RESULT CDataQueue::popDataFromQueue(){
::EnterCriticalSection(&m_stCriticalSection);
ST_MONITORING_RESULT data = m_deQueue.front();
m_deQueue.pop_front();
::LeaveCriticalSection(&m_stCriticalSection);
return data;
}
Sitting at the top of the <queue> header from the MS implementaiton of the standard library, we find...
// queue standard header
#pragma once
#ifndef _QUEUE_
#define _QUEUE_
Which means your usage of that identifier for your own header fencepost is precluding the MS header body from being pulled in. Thus, no std::queue for you. Use a different id, preferably something that doesn't violate usage rules for macro constants reserved for the implementation (like this one).
And that, kids, is why we don't use identifiers reserved for implementation usage. For more information, read this question: "What are the rules about using an underscore in a C++ identifier?"
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/