I am trying to include both "NTSecAPI.h" and "Winternl.h", but I am getting "Redefinition; different basic types" errors in whatever header file I include last.
Code:
#include <Winternl.h>
#include <NTSecAPI.h>
Error Messages:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\NTSecAPI.h(3336,28): error C2371: 'UNICODE_STRING': redefinition; different basic types
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\Winternl.h(74): message : see declaration of 'UNICODE_STRING'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\NTSecAPI.h(3336,45): error C2371: 'PUNICODE_STRING': redefinition; different basic types
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\Winternl.h(75): message : see declaration of 'PUNICODE_STRING'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\NTSecAPI.h(3337,20): error C2371: 'STRING': redefinition; different basic types
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\Winternl.h(59): message : see declaration of 'STRING'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\NTSecAPI.h(3337,29): error C2371: 'PSTRING': redefinition; different basic types
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\um\Winternl.h(60): message : see declaration of 'PSTRING'
I know you can solve this problem in C by using namespaces, but I am coding in C.
Is there any way to solve this problem without switching programming languages?
CodePudding user response:
sometime different windows headers conflict - the some class/struct/enum/function defined in both files and second definition produce error. frequently this can be resolved by put headers to namespace but from another side can create another problems. and always need look place where conflict - frequently conflict definitions was inside conditional #if block. exactly this was in concrete case -
inside NTSecAPI.h
#ifndef _NTDEF_
typedef LSA_UNICODE_STRING UNICODE_STRING, *PUNICODE_STRING;
typedef LSA_STRING STRING, *PSTRING ;
#endif
so solution in this concrete case very simply
#include <Winternl.h>
#define _NTDEF_
#include <NTSecAPI.h>
define _NTDEF_
before include NTSecAPI.h
(fortunately this not affect any other definitions in NTSecAPI.h
)