Visual Studio Compile Warning: Using system operator==/!= for GUIDs - c++

I am trying to convert a Windows driver project from using the DDK build system and Makefiles into a project that can be compiled from within Visual Studio 2012.
I've followed this guide for setting up the project options, but I am getting this warning when I try to compile:
warning : Using system operator==/!= for GUIDs
I guess there is a project configuration flag that I can set that will fix this. Any help appreciated.

This is because using ==/!= on a GUID may not yield correct results, since the GUID is a non-trivial structure type.
When compiled as C++, guiddef.h implements ==/!= using this: IsEqualCLSID on MSDN
In your case, the problem is that the DDK header is unable to implement the C++ operator overloads for ==/!= GUIDs. It looks to me like this would happen because guiddef.h is being included prior to including the DDK headers. Apparently guiddef.h and the DDK don't agree on how the ==/!= operators should be implemented, and so the DDK issues a warning.
So my guess is that all you really need to do is revisit the includes order. Also, I can't verify it since I don't have VS 2012 handy, but its quite possible that this warning itself is the only thing 'new' and that the actual behavior of the program may be unchanged from VS2008. VS2008 may very well have done the same thing but failed to issue a warniner to alert the programmer. In which case, if it worked in the old compiler then it probably should work in the new one too.

From here, that warning is given by:
#if defined(_SYS_GUID_OPERATOR_EQ_)
#define _GUID_OPERATORS_
#pragma message("WARNING: Using system operator==/!= for GUIDs")
#endif
And it looks like that can be disabled by defining _NO_SYS_GUID_OPERATOR_EQ_. So try a compiler option of /D_NO_SYS_GUID_OPERATOR_EQ_.
However, I don't recommend doing something unless you know why you're doing it. Perhaps you're supposed to supply your own overloads?

Related

IntelliSense in Visual Studio 2019 with CMake Project and IAR Compiler

So I have a CMake project which I open in Visual Studio 2019 with the "Open Folder" option. From here I can build and compile it without any errors (CMake is using the IAR Compiler (iccarm.exe) as specified in the toolchain file). So far so good.
The problem is that IntelliSense, despite finding all necessary header files, shows lots of errors mainly related to "undefined __INTxx_T_TYPE__".
As far as i know thouse double underscores indicate that it's a compiler internal data type, which is not defined in any header file, which would also explain why IntelliSense reports that it's not defined (even if the compiler knows the type). I guess to counter this problem, IntelliSense does support different modes like "windows-msvc-x86" or "linux-gcc-arm". But there is no option for IAR compiler.
So my question: How can I get IntelliSense running in this project ? Is there a way to add a custom IntelliSense mode for the IAR compiler ? Can i add header files only for IntelliSense in which the missing types are defined ? Is there a way to tell IntelliSense not to worry about those types / ignore the types ?
Ok just for the unlikely case someone has the same problem, here is my "solution" (sort of):
I created a header file with all the internal types used by IAR and called it "intellisenseHeader.h". You can find the internals here (https://www.gaio.co.jp/support/user/faq/winams/docs/sample_predef.pdf), but in my case i had to add some definitions by myself. The problem is now, that it won't compile anymore, because the IAR compiler, now finds 2 definitions (the internal definition and the one in the header file). So we need to fix this again:
I put the include inside a #ifdef USE_INTELLISENSE_HEADER.
I created two Visual Studio configurations. In the first one, CMake will set the preprocessor directive and the intellisenseHeader file will get included. In the other one i didn't set it.
So what's the effect of this ? If you are in the configuration, where the header is included, IntelliSense works but you can't compile. And if you are in the other one you can compile, but IntelliSense doesn't work anymore. So now i need to switch between the configurations, everytime i want to compile or write some code... Not the best solution but still better than nothing.
EDIT: Ok just realized you can use __INTELLISENSE__ as mentioned in # Richard Critten comment, and therefore don't need to use multiple configs.

Specify delay loading dll with #pragma in the cpp file

I have a static-linked library which uses some functions from a dll which i need to delay-load. So in my executable's properties i've added this dll under Linker/Input/Delay Loaded DLLs. I can't add this option in the lib itself since it doesn't have the Linker property pages (because it's a static lib)
So now whenever i use this lib in another executable tool i need to add the delay-loading option over and over again, which i want to avoid. I know there used to be a pragma for this
#pragma comment(linker, "/DELAYLOAD:mydll.dll")
However it doesn't work for me because it says
warning LNK4229: invalid directive '/DELAYLOAD:mydll.dll' encountered; ignored
Is there a way out, other than LoadLibrary?
Did some research on google (guess as you) as I am alway interested in such matters. The obviously link is:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/807606af-f7d7-4d9b-a9f3-062b23fddb2b/using-the-delayload-linker-switch-with-a-custom-dll
Unfortunately it is from 2004, that' nine years and some VS versions before.
But it get worser, I found also this:
http://bytes.com/topic/net/answers/280580-delayload-pragma-fixed-whidbey
which is a year late and sounds very plausible:
No, this never worked reliably. It was a bug to allow it in 6.0. One
that we fixed later by adding the warning.
Ronald Laeremans
Visual C++ team
I knew, beside your three suggestions no additional, other way.

What is sdkddkver.h?

When I attempt to compile a MFC project I get told I need to include this file. What and where is it? Why do I need it?
It's a rather important Windows SDK header file, the very first one that gets #included in <windows.h>. It declares Windows version numbers, the kind you should use in your program that states what version of Windows you want to be compatible with. The MSDN Library article is here.
If this file is actually missing on your machine (it isn't clear from the question) then you've either got a very old SDK version and are mixing headers (very bad) or you've got some disk damage (very very bad). It is the kind of problem you'd get when you are stuck on an ancient version of Visual Studio and are trying to use modern Windows api functions. Do not mix and match, it won't come to a good end.

Is bscmake needed using Visual Studio 2010?

I'm wondering if bscmake is still needed for Visual Studio 2010 C++ Projects using unmamanged/managed code.
My understanding of bscmake is, that it is generating browse-files for each cpp-file in order to be able to use things in visual studio like the "class view" or "go to definition",...
But after asking a question about bscmake myself and reading other similar questions I was unsure what bscmake is for and why you should use it.
References:
How to get rid off “BSCMAKE error BK1500: Internal error” compile errors
LINK : fatal error LNK1000: Internal error during BuildLibrary
So my question is:
Is there any need to activate bscmake?
Advantages/Disadvantages activating bscmake?
bscmake seems no longer be supported for VS2010, see this bug reports:
Per-project Browsing in VS2010 and BSC files cannot be used.
So you can speed up your compile times by turning off the creation of SBR/BSC files,
as they are useless anyway.
BSC files had the big advantage that they could be used to browse external libraries which
were not part of your solution (MFC for example). This seems not be possible with
intellisense. I personally use VisualAssist as a replacement (which works quite well for me).
The intellisense does not need the browse information, it is used for object explorer which I have never used or needed to : http://msdn.microsoft.com/en-us/library/kbs280h1%28v=vs.80%29.aspx
The main disadvantages are longer builds, build errors due to being unable to build the bsc files.
The main advantages are you can view more information of your classes and objects and apparently they have added some feature called 'live browsing' since VS2005 http://msdn.microsoft.com/en-us/magazine/cc163658.aspx.
However I have to say that the intellisense has worked fine for me, plus I use VisualAssist and I have never needed the object browser and find that the additional compilation time and build errors is so frustrating for large solutions that I never have this switch on.

Find never-called functions

I'm doing some refactoring in a project using Qt with Visual Studio 2008, and I'd like to know if there's a simple way to find the functions and methods that are never called?
You can try a static code analysis tool, like http://en.wikipedia.org/wiki/Cppcheck
A -Wall in your compilation options should do it. (Or -Wunused-function). Check the compilator options in VS.
I've always preferred "grep", but that may be a bit "old-school".
Visual Studio will build a call-graph for you that is helpful but not 100% reliable.
Another alternative is comment out the function and see if the project will still link.
Is there a chance to build this Qt Project using gcc? If so, you could use gcov. It tells you all methods which were called during execution. Then you could use ctags to create a list of all methods available. From these two sets you could find those, not being called.
Of cause the application should run long enough under gcov for delivering more or less complete list of used functions.
(I guess there is an easier way using linker or a compiler switch. :-))