C#"托管输出" [英] C# "Unmanaged Exports"

查看:179
本文介绍了C#"托管输出"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图使用扩展托管输出,由罗伯特捷在Visual Studio 2010中PRO / C#项目。然而,我不能使它工作 - 当我检查出口已编译的DLL,观众( HTTP ://www.nirsoft.net/utils/dll_export_viewer.html )总是出现空的,没有出口似乎都被定义

I've been trying to use the extension "Unmanaged Exports" by Robert Giesecke in a Visual Studio 2010 pro/C# project. Yet, I can't make it work - when I check the compiled DLL for exports, the viewer (http://www.nirsoft.net/utils/dll_export_viewer.html) always comes up empty, no exports seem to be defined at all.

我所有,但复制的例子,并设置构建/配置经理/主动平台86。我能以某种方式检查MSBuild任务,它的所有神奇的是实际运行或不?我应该在项目文件包含(这似乎是可疑的空给我吗?)

I have all but copied the example and set build/config manager/active platform to x86. Can I somehow check if the MSBuild task that does all the magic is actually run or not? What should the project file contain (it seems to be suspiciously empty to me?)

推荐答案

我会建议你这样做的记录方式,而不是依靠从一个作家谁不提供支持一个无证的黑客。让我们用一个例子来做到这一点:

I would recommend you do this the documented way instead of relying on a undocumented hack from an author who doesn't provide support. Let's do it with an example:

namespace Publics {
    public class Class1 {
        public static void Run() { 
            // Stuff...
        }
    }
}

添加一个新的C ++ / CLI类库到项目中。用鼠标右键单击该解决方案,添加新项目。打开其他语言节点时,Visual C ++,CLR,并选择了类库项目模板。右键单击新项目,属性,一般属性,框架和参考文献中,单击添加新引用按钮。从项目选项卡,挑C#项目要导出的方法(S)。

Add a new C++/CLI class library to your project. Right-click the solution, Add, New Project. Open the "Other Languages" node, Visual C++, CLR, and pick the "Class Library" project template. Right-click the new project, Properties, Common Properties, Framework and References, click the Add New Reference button. From the Projects tab, pick the C# project whose method(s) you want to export.

删除与// TODO注释pre-生成的空类,并用这种code的:

Delete the pre-generated empty class with the //TODO comment and write this kind of code:

extern "C" __declspec(dllexport)
void __stdcall Example() 
{
    Publics::Class1::Run();
}

构建您的解决方案。检查实例功能得到了通过运行该DLL DUMPBIN.EXE /出口出口。你应该看到类似这样的:

Build your solution. Check that the Example function got exported by running dumpbin.exe /exports on the DLL. You should see something similar to this:

      1    0 00001020 _Example@0 = _Example@0

除了名字和调用约定,你现在也有很多选择来调整导出的函数。如果要导出一个实例方法,而不是一个静态方法,你可以这样写的功能,例如:

Beyond the name and the calling convention, you now also have lots of choices to tweak the exported function. If you want to export an instance method instead of a static method you could write the function like this for example:

extern "C" __declspec(dllexport)
void __stdcall Example() 
{
    Publics::Class1^ obj = gcnew Publics::Class1;
    obj->Run();
}

诸如此类,是,如果你打算让这出精心设计需要一些熟悉的C ++ / CLI语言。最后但并非最不重要的,你也可能会发现出了什么毛病在原始企图使捷的IL重写工作。它以其他方式使用的C ++ / CLI编译器使用导出的管理方法完全相同的技术。

Etcetera, some familiarity with the C++/CLI language is required if you are going to make this elaborate. Last but not least, you are also likely to find out what went wrong in your original attempt to make Giesecke's IL rewriter work. It otherwise uses the exact same technique that the C++/CLI compiler uses to export the managed method.

这篇关于C#"托管输出"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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