创建混合模式C ++ / CLI DLL [英] Create a mixed mode C++/CLI DLL

查看:225
本文介绍了创建混合模式C ++ / CLI DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望不要重复已经提出的问题。我搜索,但我没有找到类似的东西。

我开发了一个原生的sdk,类和接口。

现在,我需要实现使用此SDK的混合模式DLL。

但以下代码不能编译:


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;
}

设置为:

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'

因为NativeClass没有使用/ clr编译。\\
我想我需要使用#pragma mananaged / unmanaged指令,但我不知道如何。

有人能给我一些建议吗?

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?

推荐答案

你需要添加另一层间接,所以你的非托管源文件没有看到 WrapperClass 类的内容。

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;
}

然后在WrapperClassWrapper.cpp中实现它, 。

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

这篇关于创建混合模式C ++ / CLI DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆