Click here to Skip to main content
15,894,343 members
Articles / Web Development / HTML

C# Com

Rate me:
Please Sign up or sign in to vote.
4.78/5 (36 votes)
22 Oct 2014CPOL5 min read 319.7K   6.1K   137  
Accessing a C# .NET DLL in VB6 using Com+ or Com Interop
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ComInterOpExample
{
    [Guid("69C85C8D-DBEB-4d85-83A7-7E5077AD11BA")]
    [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface iInterface
    {
        [DispId(1)] int PerformAddition(int a, int b);
        [DispId(2)] int PerformDeletion(int a, int b);
    }
    
    [Guid("0C216A19-E1B7-4b05-86D3-4C516BDDC041")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("ComInterOpClass")]  
    public class ComInterOpClass:iInterface
    {
        #region iInterface Members

        public int PerformAddition(int a, int b)
        {
           // throw new Exception("The method or operation is not implemented.");
            try
            {
                return a + b;
            }
            catch
            {
                return 0;
            }
        }

        public int PerformDeletion(int a, int b)
        {
            //throw new Exception("The method or operation is not implemented.");
            try
            {
                return a - b;
            }
            catch
            {
                return 0;
            }
        }

        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions