2

I've created C++ DLL project, this dll contains mostly native c++ code, but it have 1 mixed class written in C++ and using some .NET types. This class is declared in header file and have implementation in .cpp

I can use it from all *.cpp files, but when i try to declare reference to C++/CLI class in some c++ header file i got tons of errors about project doesnt support CLR(CLR support in project settings as /clr is set up), it looks like header files doesnt support links to managed classes.

This works from .CPP perfectly but fails with errors when used from .H

#include "NativeBitmap.h"
using namespace Native;

NativeBitmap.H:

#pragma once
namespace Native
{
    using namespace System;
    using namespace System::Drawing;
    using namespace System::Collections::Generic;
    using namespace System::Runtime::InteropServices;

    public ref class NativeBitmap
    {
    }
}

NativeBitmap.CPP:

#include "stdafx.h"
#include "NativeBitmap.h"

using Native::NativeBitmap;

using namespace System;
using namespace System::Drawing;
using namespace System::Collections::Generic;
using namespace System::Runtime::InteropServices;

void NativeBitmap::Create(...)
{
...
}

and so on ...
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
sfireman
  • 183
  • 4
  • 9
  • not sure if I understand you correctly, but why do you #include a header with a mixed class from a native cpp file? you cannot use the mixed class in a native class. Anyway the question would be more clear if you give the most basic code sample of what fails; terms like 'some file' and 'use it from all cpp files' are a bit vague. – stijn Jun 23 '12 at 10:12
  • Why i cannot use mixed class in native class? I saw examples of free mixing C++/CLI and native C++ in one project(now project compiles fine only if not use C++/CLI and native C++ together or do it only from .CPP not .H files)... or i wrong and misunderstand theme? – sfireman Jun 23 '12 at 10:20
  • 1
    you can use a native class in a mixed class, not vice-versa (if you do that the native class would have to be a mixed class as well..) – stijn Jun 23 '12 at 10:34
  • 1
    Core issue here is that you can't execute managed code without also loading the CLR. If you like to use managed code just because it has some classes that are useful in your native C++ project then write that off as an option. – Hans Passant Jun 23 '12 at 11:00

0 Answers0