using C# DLL in VB6

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
 
D

David Browne

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
 
J

José Joye

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é
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top