Click to See Complete Forum and Search --> : VB.NET registering COM interop


James Longstreet
March 15th, 2002, 04:29 PM
HI all:

having a problem tyring to register a dll for cominterop....keep getting error :

COM Interop registration failed. Access to the registry key is denied.

now what registry key I have no idea, I haven't found a thing on MSDN. I am on a Win2K box and have administrator rights

thanks!


Jim Hewitt
Software Developer
Liberty Tax Service
www.LibertyTax.com

S BUTLER
March 24th, 2002, 07:18 PM
I assume you are just setting a reference to a standard Vb dll from a Vb.Net project?

Is this dll registered on your machine. Can you find the dll in your registery?

James Longstreet
March 25th, 2002, 08:33 AM
Hi:

It is when I am trying to build a new VB.NET DLL with a COM class. I build the DLL and it gives me the message 'Com interop registration failed. access to the registry key denied'.

I have tried on a 2000 box, and an XP box with the same results. I cannot find registry permissions in 2000, but I had full permission to all keys on the XP box.

I looked on the MS website, and there was one problem with this message, but it involved collections, which I am not using...even still I tried their rememdy, which promptly gave me the same error as I am getting when building.

thanks for the reply.



Jim Hewitt
Software Developer
Liberty Tax Service
www.LibertyTax.com

Iouri
March 25th, 2002, 09:07 PM
VS.NET lets you reference and use COM DLLs much as you reference and use .NET DLLs. Start by
rummaging up a COM DLL. Open the VB6 IDE, create a new ActiveX DLL project, and name it COMdll, using
the Project Properties window. Change the name of Class1 to COMclass and add this code:

In VS.NET, create a new Class Library project named NETdll. Remove the template code from the Class1.vb
file and write this code:

Public Class NETclass
Public Function _
GetString() As String
Return "A string from .NET"
End Function
Public Function _
GetNumber() As Integer
Return 42
End Function
End Class


When you compile the project, you get a simple DLL that returns a blittable numeric value and a nonblittable
text value. You can use this DLL transparently from .NET because Type I marshaling supports both data
types.

Before you can use any DLL in VB.NET, you need to add a reference to it in your project. This holds true for
both .NET DLLs and COM DLLs, and VS.NET allows you to add references to both types of DLLs from the
same dialog.

In VS.NET, use the Project | Add Reference menu option to bring up the Add Reference dialog. Click on the
COM tab, which gives you a list of all the COM components registered currently on your system. Scroll down
and select the COMdll entry (see Figure 2).
Add a couple TextBox controls and a Button control to the form, then double-click on the Button control to
bring up the code window. Add this code within the Click event:

Dim obj As New COMdll.comclass()
TextBox1.Text = obj.GetString
TextBox2.Text = obj.GetNumber
Marshal.ReleaseComObject(obj)
This code creates an instance of the COMdll component, then calls the methods on that object to populate
the display. Notice that IntelliSense is available as you enter the code. VS.NET is fully aware of the details
of the VB6 class and its methods.
The code then calls Marshal.ReleaseComObject to release the reference to the underlying COM object
Before this code will work, you need to add an Imports statement to the top of the file:

Imports System.Runtime.InteropServices
This provides the namespace where the Marshal class resides



Iouri Boutchkine
iouri@hotsheet.com