none
How to expose C# method to unmanaged code? RRS feed

  • Question

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

    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)
           {
               .
               .
               .
           }
        }

    I acquired GUID from CreateGUID.

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

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

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

    Can anybody give me any advice regarding this issue?

    Tuesday, January 8, 2019 9:21 PM

All replies