Click here to Skip to main content
15,896,269 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.9K   6.1K   137  
Accessing a C# .NET DLL in VB6 using Com+ or Com Interop
��

<big><b>To create COM+</b></big>

<br />

Create a new c# .net class library project in visual studio 2005

<pre>

1>Open AssemblyInfo.cs  file ()Properties/AssemblyInfo.cs) in VS2005



 Set following option

 [assembly: ComVisible(true)]



 

2> Go to references folder -> right click -> add references (In .Net tab)

Add reference : System.EnterpriseServices 



3)Open a class file (ComPlusClass.cs)

 

   refer Enterprise Service as 

   <ul>using System.EnterpriseServices</ul>

 

Above namespace of this class add following statements:

 

[assembly: ApplicationName("ComPlusExample")]

[assembly:Description("ComPlus Assmebly")]

[assembly:ApplicationActivation(ActivationOption.Server)]

[assembly:ApplicationAccessControl(false)]

 



Create an interface e.g. iINTERFACE

<code>

    public interface iInterface

    {

        int PerformAddition(int a,int b);

        int PerformSubtraction(int a,int b);

    }

 </code>



Create class implementing interfaces 

   i)ServicedComponent

   ii)iINTERFACE 



To track events in COM+ for this class, add following statements as

 

[EventTrackingEnabled(true)]

[Description("Serviced Component")]





  <code>

  [EventTrackingEnabled(true)]

    [Description("Interface Serviced Component")]

    public class ComPlusClass:ServicedComponent,iInterface

    {



        #region iInterface Members



        int iInterface.PerformAddition(int a, int b)

        {

           // throw new Exception("The method or operation is not implemented.");

            try

            {

                return a + b;

            }

            catch

            {

                return 0;

            }

        }



        int iInterface.PerformSubtraction(int a, int b)

        {

            //throw new Exception("The method or operation is not implemented.");

            try

            {

                return a - b;

            }

            catch

            {

                return 0;

            }

        }



        #endregion

    }



  </code>





 4> Build the Application 

Assign strong key to Application using vs 2005 command prompt

//goto start-> program files->visual studio 2005-> visual studio tools ->sdk command prompt



sn -k ComPlusClass.snk

 

Add this strong key to Application Properties -> Signing -> Strong key



 

5>Registering Assembly:

 

Use VS tool to register assembly as

 

regasm ComPlusExample.dll

 

Create Type Library using tool 

 

tlbexp ComPlusExample.dll

 

Register it in COM+ as

 

regsvcs ComPlusExample.dll

 

 

 

To view this registered COM+

 

Go to Control Panel -> Administrative Tools -> Compoent Services

 

In Component Services -> Computers -> My Computer -> Com + Applications

 

Here it is.................................

 

Refer tlb of assembly from Release folder to use in VB6 applications



</pre>

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