Options

Easy way to make a com DLL in c#?

2»

Comments

  • Options
    kauffmannkauffmann Member Posts: 56
    kine wrote:
    How can I unregister the .net interop DLL? (I know only the way of regsvr32 but this is not the correct one in this case)

    Use regasm with the /unregister switch at the command line.
    A good programmer makes al the right mistakes
    My blog
  • Options
    kinekine Member Posts: 12,562
    Thanks.

    I have still problems. If I use AutoDual for the class, all is ok. In .tlb file there are all method etc. If I do not use AutoDual there is only the class without members. Never the Interface... :-s

    May be that problem is that the class is inherited from the Form class and is using some Interface (and not only the interface without inheritating...)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    kauffmannkauffmann Member Posts: 56
    As promised, I tried your code in Visual Studio 2005.

    It turns out that we both overlooked one little keyword 'public'... :oops: :!:
    public interface IWrapperClass
    

    Without making your interface public, Navision will never be able to determine the correct interface of the class when the ClassInterfaceType = None.

    Remember, you should set the InterfaceType to ComInterfaceType.InterfaceIsIDispatch (which is default)
    A good programmer makes al the right mistakes
    My blog
  • Options
    kauffmannkauffmann Member Posts: 56
    kine wrote:
    How can I unregister the .net interop DLL? (I know only the way of regsvr32 but this is not the correct one in this case)

    One other (much simplier way) to unregister: just remove the "Register for COM Interop" checkmark in the project properties and rebuild the project. This will unregister the dll for COM.
    A good programmer makes al the right mistakes
    My blog
  • Options
    kinekine Member Posts: 12,562
    It is working now. Final version:

    Interface:
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [ComVisible(true)]
        [GuidAttribute("some GUID")]
        public interface IMyInerface
        {
            [DispId(1)]
            void AboutBox();
    
            [DispId(2)]
            short SomeProperty { get; set; }
    ...
    

    Class:
        [ClassInterface(ClassInterfaceType.None)]
        [ComVisible(true)]
        [GuidAttribute("another GUID")]
        public partial class MyClass : SomeOtherClass, IMyInterface
        {
            public void AboutBox()
            {
    ...
            }
    ...
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    lzrlzr Member Posts: 264
    How do you expose attributes of a com class? I can expose my methods but not my attributes..

    EDIT: God damn, I forgot public ](*,)
    Navision developer
  • Options
    ShenpenShenpen Member Posts: 386
    Hi,

    I am trying to do it without Visual Studio, because that costs money you know :D with the free SharpDevelop IDE. The problem is that this IDE does not provide a project option for registering as a COM object.

    So what I am trying to do is the following:

    code taken from an example mentioned earlier in this topic
    using System;
    using System.Runtime.InteropServices;
    	
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface GeneralNavTest
    	{
    	int Add2Numbers(int a, int b);
    	}
    
    [ClassInterface(ClassInterfaceType.AutoDual)] 
    	public class NavTest : GeneralNavTest
    	{
    		public NavTest()
    		{
    			
    		}
    		
    		public int Add2Numbers(int a, int b)
    		{
    			return(a+b);
    		}
    		
    		
    	}
    

    and then I copy it to the Navi client folder, and then
    "c:\Windows\Microsoft.NET\Framework\V1.1.4322\RegAsm.exe" "c:\Program Files\Microsoft Business Solutions-Navision\Client\navtest2.dll" /tlb:navtest2.tlb
    

    what happens is that the registration is successful, but it does not appear in Navision under Custom Controls in Tools menu.

    Any ideas?

    Do It Yourself is they key. Standard code might work - your code surely works.
  • Options
    kinekine Member Posts: 12,562
    You have no
        [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
        [ComVisible(true)]
    
    lines in your example...(and others)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    ombackeombacke Member Posts: 44
    In order to use a C# dll in Navision the dll must have a strong name. U need a keypair. U can create one using sn.exe. There should also be an interface in you .net application with the public methods..

    Once the dll is compiled with the key, you need to put it in the assembly folder and register it using regasm.. Then you're set
  • Options
    lzrlzr Member Posts: 264
    Shenpen wrote:
    Hi,

    I am trying to do it without Visual Studio, because that costs money you know :D with the free SharpDevelop IDE. The problem is that this IDE does not provide a project option for registering as a COM object.

    So what I am trying to do is the following:

    code taken from an example mentioned earlier in this topic

    what happens is that the registration is successful, but it does not appear in Navision under Custom Controls in Tools menu.

    Any ideas?

    I just use that code and then put "com visible" and "register for com interop" attribute to TRUE and then it registers it for Navision automatically.
    Navision developer
Sign In or Register to comment.