0


I hope not to repeat something already asked..I search around but I haven't found something similar.
I have developed a native sdk which expose some classes and interfaces.
Now, I need to implement a mixed mode DLL which uses this SDK.
But the following code does not compile:

WrapperClass.h

#pragma once

#include <vcclr.h>

#using <mscorlib.dll>

class WrapperClass{
public:
  WrapperClass();

private:
  gcroot<Client^> m_ManagedObj;
};

NativeClass.h

#pragma once

#include "stdafx.h"
#include "NativeSDK.h"

#include "WrapperClass.h"

class Native : public INativeSDK {
public:
  // ... code ...

private:
  WrapperClass ManagedObj;
}

The settings are:

Project Setting   : No Support for CLR
NativeClass.cpp   : No Support for CLR
WrapperClass.cpp  : /clr

The compiler error is:

..\include\vcclr.h(16): fatal error C1190: The managed code require an option '/clr'

Because NativeClass is not compiled with /clr.
I suppose I need to use #pragma mananaged/unmanaged directive but I cannot figure out how.
Could someone give me some suggestions?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
Barzo
  • 1,039
  • 1
  • 11
  • 37
  • You are not close, too many things wrong to explain. Look at [this answer](http://stackoverflow.com/a/2691448/17034) for the recipe for a managed wrapper. – Hans Passant May 29 '13 at 18:02
  • Thanks for you answer @HansPassant, let me if I wrong but, that example (which I already seen) explain how to wrap a native object into a managed one...I need to do the opposite. – Barzo May 31 '13 at 11:30

1 Answers1

1

You many need to add another layer of indirection, so your unmanaged source files don't see the "contents" of the WrapperClass class.

//WrapperClassWrapper.h
class WrapperClass;

class WrapperClassWrapper
{
public:
    WrapperClassWrapper();
    ~WrapperClassWrapper();
    //etc.
private:
    WrapperClass *m_pWrapper;
}

And then you implement it in a WrapperClassWrapper.cpp which you compile with /clr.

Medinoc
  • 6,577
  • 20
  • 42