Why is SRWLock undefined? - c++

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>

Related

identifier "CvRTrees" is undefined

I'm using openCV-3.2.0 and getting an identifier undefined error when initializing the line :
CvRTrees rtrees;
I think i have added all the necessary header files. So why am i getting this error?
#include <stdio.h>
#include<conio.h>
#include <opencv/cv.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.h>
#include <opencv/ml.h>
#include <opencv2/core/core.hpp>
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <math.h>
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <exception>
#include <array>
#include "opencv2/ml/ml.hpp"
using namespace std;
using namespace cv;
This class exists in OpenCV 2.4.x, However it is not available in newer versions of OpenCV like 3.2.0. Check here the list of all cv::ml classes for OpenCV 3.2.0. I suggest you to use RTrees instead. To do this you do not need to include all headers, just include the machine learning module:
#include "opencv2/ml/ml.hpp"

VSC “Format Document” messes up #include order

My problem is pretty much what the title says:
When I use STRG-ALT-F to format my C++ files VSC also messes with the order of #includes.
And of cause this leads to errors that were not there before… :-(
For example this
#include "soc/soc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "XClk.h"
#include "DMABuffer.h"
becomes this
#include "DMABuffer.h"
#include "XClk.h"
#include "driver/gpio.h"
#include "driver/periph_ctrl.h"
#include "rom/lldesc.h"
#include "soc/gpio_sig_map.h"
#include "soc/i2s_reg.h"
#include "soc/i2s_struct.h"
#include "soc/io_mux_reg.h"
#include "soc/soc.h"
… and subsequently fails compile.
Is there a way to forbid the formatter reordering and stick to formatting stuff?
Using PlatformIO in VSC on OSX.

why #include <iostream> is not used in driver development

#include <DriverSpecs.h>
_Analysis_mode_(_Analysis_code_type_user_code_)
#define INITGUID
//#include<iostream>
#include <windows.h>
#include <strsafe.h>
#include <cfgmgr32.h>
#include <stdio.h>
#include <stdlib.h>
#include "public.h"
When I tried to use <iostream> in a sample driver solution I got an error.
I'd like to know if is it possible to get input or output while a driver is running.

Weird VC++ Intellisense Behavior

Intellisense is broken with this code, everything is undefined to Intellisense from tree header:
#include "tree.h"
#include <iostream>
#include <ctime>
#include <string>
#include <list>
But when I move my own bst implementation header file down a bit, Intellisense starts working again.
#include <iostream>
#include <ctime>
#include <string>
#include <list>
#include "tree.h"
Why is this?

why does it matter if the #include are in the .h file or in .cpp file?

I have a cpp file contains this include:
#include "twitServer.h"
and in twitServer.h I have:
#ifndef twitServer_twitServer_h
#define twitServer_twitServer_h
#include <string>
#include <map>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <cstring>
#include <netdb.h>
#include <errno.h>
#include <sstream>
#include <algorithm>
#include <ctime>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include "twitUser.h"
using namespace std;
void startServer(string port);
#endif
But the Xcode says for this line:
if ((rv = getaddrinfo(NULL, port, &hints, &ai)) != 0) {
fprintf(stderr, "selectserver: %s\n", gai_strerror(rv));
exit(1);
}
that the getaddrinfo is not defined... why that?
if the includes are in the cpp file it works fine how comes
Not sure how to fix your problem, but by convention, you should never include in the header file, because you might write code some day, needing your header file, but not all the includes.
Try including Ws2tcpip.h and see if that solves the problem. This is what MSDN has to say about it (see the requirements section)
http://msdn.microsoft.com/en-us/library/windows/desktop/ms738520%28v=vs.85%29.aspx
Also, let me say that this seems like an awful lot of header files included and some should not be matched unless you really know what you are doing. There are quite a bit of C++ headers (iostream (which is included twice by the way), cstdio, cstdlib, algorithm, list, string, ctime...) mixed with C headers (stdio.h, stdlib.h string.h). Maybe it's time for some late spring cleaning in there :)