如何将C#方法暴露给非托管代码? [英] How to expose C# method to unmanaged code?

查看:67
本文介绍了如何将C#方法暴露给非托管代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从非托管代码(如VC ++或VB6)调用我的C#dll。

I want to make my C# dll called from unmanaged code like VC++ or VB6.

为此,我将GUID添加到接口和类,如下面的代码。 / p>

To do this, I added GUID to the interface and class like following code.

namespace MyProject
{
    [Guid("377B500A-CAAA-4e87-B7AC-84C76A555851")]
    public interface IMyInterface
    {
        bool Show(string filepath, IWin32Window owner);
    }

    [ClassInterface(ClassInterfaceType.None)]
    [Guid("BBABC433-DBC8-4287-ADFA-B72AD1CF539A")]
    public partial class MainForm : Form, IMyInterface
    {
       .
       .
       .
       public bool Show(string filepath, IWin32Window owner)
       {
           .
           .
           .
       }
    }

我从CreateGUID获得了GUID。

I acquired GUID from CreateGUID.

我使用gacutil向GAC添加了程序集成功使用REGASM注册我的COM程序集。

I added assembly to the GAC using gacutil and registered my assembly for COM by using REGASM successfully.

此代码应将接口和Show()方法公开给非托管代码。

This code should expose the interface and Show() method to the unmanaged code.

但是我无法从VC ++中看到界面或方法。

However I can't see the Interface or method from VC++.

有人可以就此问题给我任何建议吗?

Can anybody give me any advice regarding this issue?

推荐答案

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home? forum = vcgeneral

https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vcgeneral

也许,你应该发帖到VC ++论坛。

Maybe, you should post to the VC++ forum.


这篇关于如何将C#方法暴露给非托管代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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