1
I created a very basic DLL in C# just for testing. It looked like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace CriarDLL
{
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("EB331808-BC1C-4B13-9ADC-E634E9102DF4")]
public interface ICalculator
{
int AddNumbers(int x, int y);
int SubNumbers(int x, int y);
int MultNumbers(int x, int y);
double DivNumbers(int x, int y);
}
[ComVisible(true), ClassInterface(ClassInterfaceType.None),
Guid("0BE3D996-63ED-4861-9310-05985C5FFA8E")]
public class Calculator : ICalculator
{
//O construtor não pode conter parametros.
public Calculator()
{
}
public int AddNumbers(int x, int y)
{
return (x + y);
}
public int SubNumbers(int x, int y)
{
return (x - y);
}
public int MultNumbers(int x, int y)
{
return (x * y);
}
public double DivNumbers(int x, int y)
{
return (x / y);
}
}
}
I did all the scoring processes Register for COM interop
, marquei Sign the assembly
and created a Strong Name Key
, transformed Assembly Global
(GAC), I created in services and components a COM+ Application (which shows the methods that are in the class).
Then I created another project in C# (Windows Forms) to test the DLL, when I went to add a reference in the COM tab, the DLL was there, but when I clicked OK the following message appeared:
A Reference to 'Criadll' could not be Added. The Activex type library 'local Criadll.tlb' was Exported from a . NET Assembly and cannot be Added as a Reference. Add a Reference to the . NET Assembly Instead.
Does anyone know if I did anything wrong? Or if something is missing?
If I add a DLL by the Browser tab it works normally but if I try to add by the COM tab that error I posted.
– Thiago Alex
But then your problem has been solved? You can use the DLL functions developed in . NET in the VB6 application?
– Raul Almeida
No, I thought your answer referred to Visual Studio, on VB6 I did not test. I will have to test at home to be sure.
– Thiago Alex