How to do an ActiveX DLL in VB6 Visual Studio 2005

November 3, 2009

Open visual studio 2005

create a new project ClassLibrary

 

on Project->Properties->Build

choose "Register for COM interop"

modify assemblyinfo.cs

[assembly: ComVisible(true)]


Add an interface file (IProvaNet.cs):

using System;

using System.Runtime.InteropServices;

 


namespace provanet

{

        [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)]

 


        public interface Iprovanet

        {

            void provaMetodo(string strValue);

            string provaProprieta { get; set; }

        }

}

 

 


Add a class file (CprovaNet.cs):

 


using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 


namespace provanet

{

    [ClassInterface(ClassInterfaceType.None)]

 


    public class Cprovanet : Iprovanet

    {

            private string m_prova = "empty";

 


            public void provaMetodo(string strValue)

            {

                m_prova = strValue;

            }

 


            public string provaProprieta

            {

                get { return m_prova; }

                set { m_prova = value; }

            }

    }

}


Test in .NET

Add the class library on reference:

public partial class FormTest : Form

{

        private Centera.CCentera m_Centera;

        public FormTest()

        {

            InitializeComponent();

            m_Centera = new Centera.CCentera();

}

}

 

Test in VB6


Add the class library on reference:

Dim m_Centera As centera.CCentera

Private Sub Form_Load()

    Set m_Centera = New centera.CCentera

End Sub

 


Create a "strong name":

 


run cmd

cd "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin"

 


create a public/private key pair:                      

sn -k keypair.snk

 


(If you intend to delay sign an assembly extract the public key:

sn -p keypair.snk public.snk)

 


on Project->Properties->Signing choose "Sign the assembly" and choose the .snk filename created

 

 

 

 


Release the Class Library:

 


compile provanet

 


set the PATH with the following command:

 


set PATH=C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin;C:\WINNT\Microsoft.NET\Framework\v2.0.50727;C:\Program Files\Microsoft Visual Studio 8\VC\bin;C:\Program Files\Microsoft Visual Studio 8\Common7\IDE;C:\Program Files\Microsoft Visual Studio 8\VC\vcpackages;%PATH%

 


use regasm to register (C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\regasm.exe)

REGASM provanet.dll

 


To create the tlb use:

 


REGASM provanet.dll /tlb:provanet.tlb

 


Use gacutil to add to Global Assembly Cache if you want to use .dll in a different folder of .exe (C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe)

Gacutil /i provanet.dll

 

Entry Filed under: Uncategorized. .

Leave a Comment

Required

Required, hidden

Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Trackback this post  |  Subscribe to the comments via RSS Feed


Calendar

November 2009
M T W T F S S
« Oct    
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Most Recent Posts