I have a basic C++/CLI DLL in VS 2017 which defines the wrapper class described below. The project properties are set to produce CLR with .NET 4.6.1 as target.
#include "ApiManagerWrapper.h" // very basic CLI wrapper header
#include "Handler.h" // This header is an API example that includes windows.h
using namespace System;
using namespace std;
namespace CLI
{
ApiManager::ApiManager()
: ManagedObject(new GXP_API::ApiManager())
{
Console::WriteLine("Creating a new ApiManager-wrapper object!");
}
}
I need to reuse a C++ file (handler.h, out of an API devkit) that includes itself windows.h, mainly to use HANDLE and CRITICAL_SECTION structures. I know this because if I remove the windows.h include in the handler.h header (and a good part of the code using the above mentionned structures), the CLI wrapper DLL compiles just fine.
The problem is that FILETIME is defined both in one of the headers included by windows.h (minwinbase.h) and in the namespace System::Runtime::InteropServices. The error is reported as E0266 in VS 2017 with a link to a thread, which recommends to qualify use of FILETIME with the intended usage scope (::FILETIME). This is however not possible in this case, as this header is from the OS. I also need to use the System namespace, as it is the basis on the CLI assembly mechanism.
How is it possible to resolve this conflict? Is there any way not to use a given part of the System namespace? Any way to instruct the compiler how to resolve the conflict?