Reputation: 109
I have a C++/CLI library which will be used by a WPF application. In this library I am trying to pass a managed type to an unmanaged function accepting an LPARAM
parameter only. My attempt to implement this is using gcroot
. Including gcroot.h
throws way more compiler errors, so I include vcclr.h
instead.
The problem is that as soon I include the vcclr.h
header, the compiler throws the following error:
fatal error C1190: Managed code requires a '/clr' option
But in my project properties, I already enabled CLR support under Project properties -> General
and Project properties -> C/C++ -> General
for configurations ('Debug' and 'Release') and for all platforms ('Win32' and 'x64').
The error occurs in the following line of vcclr.h
:
#using <mscorlib.dll>
Writing the same line for example in the DLL's main cpp file does not seem to cause this error.
The platform tool set I am using for my project is Visual Studio 2017 (v141)
.
I am aware that there are approximately five other questions about this error. But in my case none of the answers could help me to solve my problem. The same applies to questions regarding gcroot
.
Upvotes: 1
Views: 2413
Reputation: 510
that's a tricky question. Generally if you have "way to much error messages" and then choose the way to go over might cut the mess at the wrong end.
So the answer on your question. Do not use <vcclr.h>
if you want to use <gcroot.h>
because of errors. Just better post that errors here.
TLTR; Try to use the #ifdef _MANAGED
before your include. That will avoid that any other compile unit will read the code if it not compiled with "/CLR".
How to debug the mass of errors that occurs in an rather bigger project?
There are for sure better ways but sometimes I was going back to make sure that i do understand my compiling errors.
Well you found the bad one.
Now you will have found several reasons and according to that options:
#pragma manged(off)
before an include.
That is considered undefined behavior by Microsoft documentation of that pragma. Sorry :-/ , i learned that too, after Microsoft updated VS2017 in December.<thread> or <mutex>
and you did the pimpl-ideom and you did have a file that you could not compile with /clr
Well, back on start, refactor you project to not include the "managed" header file from those un-managed compile units.Upvotes: 2