using C# DLL in VB6

  • Thread starter Thread starter Sutapa
  • Start date Start date
S

Sutapa

Hi,

I am creating a DLL in c# and then trying to use it in VB6
and its failing.

Steps i did are :

1. code
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MyCalculator
{
public interface Calc
{
int addnum(int aa, int bb);
}

public class CalculatorCLS : Calc
{
public CalculatorCLS()
{
}

public int addnum(int aa, int bb)
{
return aa+bb;
}
}
}

2. compiled with Register with COm interop property as
true.

3. got TLB File.

4. In VB added reference to MyCalculator.tlb file.

5. Dim aa As MyCalculator.Calc
Dim cc As Integer
aa = New MyCalculator.CalculatorCLS
cc = aa.addnum(34, 45)

I get error

"File or Assembly Name MyCalculator, or one of its
dependencies, was not found."

Where I am doing wrong?

Thanks
Sutapa
 
Sutapa said:
Hi,

I am creating a DLL in c# and then trying to use it in VB6
and its failing.

Steps i did are :

1. code
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace MyCalculator
{
public interface Calc
{
int addnum(int aa, int bb);
}

public class CalculatorCLS : Calc
{
public CalculatorCLS()
{
}

public int addnum(int aa, int bb)
{
return aa+bb;
}
}
}

2. compiled with Register with COm interop property as
true.

3. got TLB File.

4. In VB added reference to MyCalculator.tlb file.

5. Dim aa As MyCalculator.Calc
Dim cc As Integer
aa = New MyCalculator.CalculatorCLS
cc = aa.addnum(34, 45)

I get error

"File or Assembly Name MyCalculator, or one of its
dependencies, was not found."

MyCalculator.dll needs to be in the current directory, the GAC or registered
with the /codebase option.

David
 
If you do not have good reason for placing it in the GAC, I will rather not
do it.
try to register your assembly with:
regasm /tlb:MyCalculator.tlb /codebase Mycalculator.dll

By the way, there is a tool (in the SDK) that allow you to see from where
dll are loaded (or failed to load):
fuslogvw (look in MSDN for more details)

José
 
Back
Top