none
Expose .Net (C#) DLL To COM RRS feed

  • Question

  • Hi everyone,

    I have tried everything, read examples and etc, but I can't expose my DLL to COM Interop.


    The project has a strong key added and checked the option Register for COM Interop but when I try to call my DLL in other apps says that can't find the entry point named ExecInClientDLL.

    Could someone show me where I'm wrong?

    Best regards,

    Renan Paiva

    Following my code:

    Class:

    using System;

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using System.Threading.Tasks;

    using System.Runtime.InteropServices;

    namespace dllProtheus

    {

        [Guid("5B38DC58-E9E4-11E4-B496-C4621D5D46B0")]

        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]

        public interface IExecInClientDLL

        {

            [DispId(1)]

            int ExecInClientDLL(int id, string parametro, string buffer, int bufferSize);

        }

        

        [Guid("69C68270-E9E4-11E4-B493-CB621D5D46B0")]

        [ClassInterface(ClassInterfaceType.None)]

        [ComSourceInterfaces(typeof(IExecInClientDLL))]

        [ProgId("dllProtheus.TesteDLL")]

        public class TesteDLL : IExecInClientDLL

        {

        

            public TesteDLL() { }

                            

            public int ExecInClientDLL(int id, string parametro, string buffer, int bufferSize)

            {

                buffer = "retorno da dll " + parametro;

                return 200;

            }

        }

    }

    My assembly:

    using System.Reflection;

    using System.Runtime.CompilerServices;

    using System.Runtime.InteropServices;

    using System.Resources;

    // General Information about an assembly is controlled through the following 

    // set of attributes. Change these attribute values to modify the information

    // associated with an assembly.

    [assemblyAssemblyTitle("dllProtheus")]

    [assemblyAssemblyDescription("")]

    [assemblyAssemblyConfiguration("")]

    [assemblyAssemblyCompany("")]

    [assemblyAssemblyProduct("dllProtheus")]

    [assemblyAssemblyCopyright("Copyright ©  2015")]

    [assemblyAssemblyTrademark("")]

    [assemblyAssemblyCulture("")]

    // Setting ComVisible to false makes the types in this assembly not visible 

    // to COM components.  If you need to access a type in this assembly from 

    // COM, set the ComVisible attribute to true on that type.

    [assemblyComVisible(true)]

    // The following GUID is for the ID of the typelib if this project is exposed to COM

    [assemblyGuid("ccc6e7d6-c921-452f-9759-cc1bac0113b1")]

    // Version information for an assembly consists of the following four values:

    //

    //      Major Version

    //      Minor Version 

    //      Build Number

    //      Revision

    //

    // You can specify all the values or you can default the Build and Revision Numbers 

    // by using the '*' as shown below:

    // [assembly: AssemblyVersion("1.0.*")]

    [assemblyAssemblyVersion("1.0.0.0")]

    [assemblyAssemblyFileVersion("1.0.0.0")]

    [assemblyNeutralResourcesLanguageAttribute("en")]


    Friday, April 24, 2015 1:29 PM

All replies

  • Hello Renan,

    I test your provided code, however, it could work on my side, since it is a .NET based COM interop component, I called it from the VBA according to this link: http://stackoverflow.com/questions/1170794/a-simple-c-sharp-dll-how-do-i-call-it-from-excel-access-vba-vb6, the result is same in the link above, it prints the string characters(I changed your provided method to return a string instead).

    >> The project has a strong key added and checked the option Register for COM Interop

    After you done this, please check the COM reference list in Visual Studio, if it is registered successfully, it should be there as below:

    >> when I try to call my DLL in other apps says that can't find the entry point named ExecInClientDLL.

    Ok, I do not reproduce this issue, would you please tell what project you used to call the .NET based COM interop component? If it is also a .NET based application, as far as I know, it is not possible to do this, you could just add a reference to that built dll rather than registered COM dll. Or if is a COM based application, I suggest you could try with the link above to check if this issue is caused by the dll or the application which could help narrow down this issue.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Sunday, April 26, 2015 1:52 AM
    Moderator
  • Fred thanks a lot for your answer.

    Let me explain to your my environment. I have and old ERP and this ERP has an entry point for DLL's since it have a module named ExecInClientDLL. This ERP isn't .Net based, ERP uses a technology about 20 years old, a fusion of Clipper and Five Win.

    So It can't be done adding the TLB resource as VBA, VB6, Delphi and etc, is almost like C. I tried doing a DLL in VC++ and works fine. I need that DLL in C# have a same behaviour as an unmanaged DLL, as C++ i.e. 

    Is this possible?

    Thanks.

    Monday, April 27, 2015 12:56 PM
  • Hello Renan,

    >>I tried doing a DLL in VC++ and works fine. I need that DLL in C# have a same behaviour as an unmanaged DLL, as C++ i.e.

    I am not quite sure about what you mean, do you mean you want to call a C++/unmanaged dll in C# application? If so, yes, you can: Call Unmanaged DLLs from C#, Killing Processes Cleanly

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 28, 2015 5:55 AM
    Moderator