CLR标志构建的本机dll包含托管类

CLR标志构建的本机dll包含托管类

本文介绍了用/CLR标志构建的本机dll包含托管类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个旧的本机MFC/c ++ dll,我设法用/CLR标志对其进行了编译.
现在,我将一个托管的C ++/CLI类添加到了namaspace中的dll中.

头文件在下面,并且cpp文件的头文件只包含#include.
本机dll是一个巨大的dll项目,其中包含许多不受托管的代码,但是它只有一个托管的c ++类,如下所示.

当我将该dll添加为对.net winforms项目的引用时,在对象浏览器中我看不到该名称空间/类,

并且由于找不到命名空间"ShashiTest"而出现编译错误

我正在使用Visual Studio2008.

不能将混合模式下的本机dll添加为对托管项目的引用?

还是我想念一些东西

请帮忙.

Hello,

I have a old native MFC/c++ dll I have managed to get it compiled with /CLR flag.
Now I have added a managed C++/CLI class to the dll within a namaspace.

The header file is below, and the cpp file only has #include for the header file.
The native dll is a huge dll project with lot of un managed code, but it has only one managed c++ class like below.

When I add that dll as a reference to a .net winforms project I don''t see that namespace / class, in the object browser,

and I get compile error for not finding the namespace "ShashiTest"

I am using Visual studio 2008.

Native dlls in mixed mode can not be added as reference to a managed project ?

Or am I missing something

Please help.

#pragma once
#using<mscorlib.dll>
#using<system.windows.forms.dll>
// Class derived from Forms

using namespace System::Windows::Forms;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Diagnostics;
using namespace System::Windows::Forms;

namespace ShashiTest {
    /// <summary>
    /// Summary for test
    /// </summary>
    public ref class test
    {
    public:
        test(void)
        {

        };
        void ShowMessage()
        {
            MessageBox::Show("Hello World");
        }
    };
}





Shashi





Shashi

推荐答案


#pragma managed(push,off)
// Unmanaged code goes here
#pragma managed(pop)


请参见将ACE与C ++ CLI结合使用 [ ^ ]的示例.

最好的问候
Espen Harlinn


See Using ACE with C++ CLI[^] for a working example.

Best regards
Espen Harlinn


这篇关于用/CLR标志构建的本机dll包含托管类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 02:30