including secExt.h causes errors - c++

I'm trying to include secExt.h in my C++ project and it gives me the error:
error C2086: 'BOOLEAN SEC_ENTRY' : redefinition
How can I fix it?

EDIT: from microsoft's docs, include security.h, not [secext.h].
original answer (before I googled the header name myself, no info given by OP):
if the header is yours, add
#pragma once
at the top.
if that doesn't work (there is reportedly a compiler on some IBM system or something that doesn't support #pragma once), then use a header guard.
if the header isn't yours, create a header wrapper like this:
#pragma once
#include <secExt.h>
then include your wrapper header instead of including [secExt.h] directly.

Related

VS2017 C++: why is PIP_ADAPTER_ADDRESSES undefined?

I'm working with a file that uses the PIP_ADAPTER_ADDRESSES type. The person who worked on this code was using VS2013 (my current job is to upgrade the codebase to VS2017). The #includes look like this:
#include <winsock2.h> // Include for security.h
#include <security.h> // Include for EXTENDED_NAME_FORMAT
#include <iphlpapi.h> // Include for PIP_ADAPTER_ADDRESSES
And I get error C2061: syntax error: identifier 'PIP_ADAPTER_ADDRESSES' when trying to compile. This appears to be a problem in VS2017 but not VS2013.
PIP_ADAPTER_ADDRESSES appears to be defined in <IPTypes.h>, which is included by <iphlpapi.h>, but it is inside an #ifdef _WINSOCK2API_ block. However, this should be defined since I included <winsock2.h>. What's going on here?
Edit: On second glance, it looks like that error message doesn't indicate that it's undefined, but rather that there is a circular dependency with this identifier. I am continuing to investigate.
It turns out that in my case there was ANOTHER file that had included <iphlpapi.h> but not <winsock2.h>, which was causing the errors in the file I was working on. For some reason, this file was being compiled first in VS2017 but not in VS2013. Make sure you check all of your includes, I guess.
I faced to similar problem. When WinSock2.h header file is not included, then PIP_ADAPTER_ADDRESSES is not declared. If WinSock2.h is included, then a lot of error messages are generated.
So, thanks to this answer, I investigated the WinSock2.h header file and I found this comment:
#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
I changed the order of the include files moving Windows.h after WinSock2.h and iphlpapi.h and this solved the issue.

Precompiled header error in Visual Studio 2015

I beg your pardon if this question has been already answered, but I have been trying to implement precompiled headers in my game engine with no success so far.
My precompiled header is called UtilBase.h:
#pragma once
#if !defined(NF3D_UTIL_BASE_H)
#define NF3D_UTIL_BASE_H
// This is a precompiled header.
#pragma message("Compiling precompiled header.")
// Include engine specific files.
#include <Utilities\Platform\Types.h>
// Include external header files (STL, Win32 API, Direct3D 11, etc)
// There are some typedefs here:
typedef __int32 int32; // And so on.
#endif
Although this is against the standards, I included UtilBase.h in other headers because I need access to some of its contents. It is also included in all .cpp files, first line, from the current project (the solution has two projects).
I need it in some headers because it stores some typedefs that are used in function declarations. For example, I have some file called Window.h:
#pragma once // And include guards that are omitted here
int32 NF3DCreateWindow();
The associated source file is called UtilBase.cpp and has only one line of code:
#include <Utilities\UtilBase.h>
The project has been set up correctly in my opinion:
for all platforms and configurations.
UtilBase.cpp has this setting:
However, when I compile I get this error:
1>Source Files\Utilities\UtilBase.cpp(2): error C2857: '#include' statement specified with the /YcD:\New Frontiers\NewFrontiers3D\Header Files\Utilities\UtilBase.h command-line option was not found in the source file
which points to the only line in UtilBase.cpp (#include <Utilities\UtilBase.h>).
Why does this happen and what can I do to make it work? I will gladly send any further information about this scenario. Thank you very much in advance.
Finally made it! For anybody in my situation here is what I did: in project settings, Precompiled Header File tag, I added $(ProjDir)\Header Files\Utilities\UtilBase.h and it was evaluated to the full path of the file. The correct way is to simply add the file: Utilities\UtilBase.h and that's it.
Thank you for your support.
try #ifndef instead of #if !defined

When trying to compile a .dll, I'm getting an error with the interface keyword

I have set up a project in Visual Studio to create a .dll. I have included an external library in the project which uses the keyword "interface". This is giving me the following error:
error C2146: syntax error : missing ';' before identifier 'INuiAudioBeam'
These are the lines of code where the error occurs:
#ifndef __INuiAudioBeam_FWD_DEFINED__
#define __INuiAudioBeam_FWD_DEFINED__
typedef interface INuiAudioBeam INuiAudioBeam; //Error on this line
#endif
The above code is part of a header file in the external library I have included. The project builds successfully without any errors when compiling without including the headers for the library (Note: Linking the library does not cause any problems).
What is the solution to this? Is it because I have an external library I'm using to create my dll? Should I create a .lib instead of a dll?
If anyone else searches this, the problem is most likely
#define WIN32_LEAN_AND_MEAN
Before
#include <windows.h>
Remove the define, make sure your including windows.h, and that should define interface keyword for you
You can get C2146 with indictment of the interface keyword. It may be confusing as to how a keyword may be undefined, especially that in other compilation units or projects that use the same header file - the inclusion of which brought about the problem - all goes smooth. However, the apparent keyword "interface" is still a compiler #define directive. It just happens to be buried inside a header file that a few developers have reasons to inspect: the <objbase.h>. There it is defined in two steps:
#define __STRUCT__ struct
#define interface __STRUCT__
Since the <objbase.h> is included by multiple other header files - such as ole2.h, oleauto.h, and a slew of ATL headers - you may be surprised with this error when none of those headers were included in the current compilation unit.

#include <afxinet.h> in a header file causes a lot of compilation error, however, include it in a cpp file is ok

the first error when putting #include <afxinet.h> in a header file
IntelliSense: #error directive: WINDOWS.H already included. MFC apps must not #include <windows.h>
(1) Any idea why this is it?
The other similar thing is if you put the headers in a wrong order, odd errors appear, whose msg do not make sense at all... this kind of behaviour of VC++ complier is driving me crazy.
(2)anyone has a solution to this kind of problem?
I had similar problem with winsock.h, something like that:
fatal error C1189: #error : WinSock.h has already been included
I've added the WIN32_LEAN_AND_MEAN preprocessor directive to my project and it fixed it.
I can't tell why, or what is the reason behind that.

Why do I get an including <iostream.h>?

I have been trying to import iostream into a custom block, I added the line
#include <iostream.h>
in the .h file and in the .cc file but I get the error:
fatal error: iostream.h: No such file or directory
The iostream header is <iostream>, not <iostream.h>. The error you're getting suggests that the compiler is looking for iostream.h, which suggests that you might be including the wrong header.
Try changing the header to <iostream> and see if that fixes the problem. More generally, make sure you aren't including any C++ standard library header files suffixed with .h unless they come from C as well (in which case you should probably use the C++ versions of the headers anyway).
Hope this helps!