14

Is it possible to use a VB6 class in C#?

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
James Jeffery
  • 12,093
  • 19
  • 74
  • 108

4 Answers4

12

I think you should just be able to add the library that contains your VB6 type as a reference in your C# project. Visual Studio will create an Interop Assembly on the fly, and you'll get access to all of the types in the VB6 library via Runtime Callable Wrappers.

The tool that creates the Interop Assembly is TLBIMP.EXE, and you can run this yourself if you want more control over the process, eg. if you want to create a Primary Interop Assembly that might be shared by multiple managed components.

lesscode
  • 6,221
  • 30
  • 58
  • w.r.t "the library", you can browse to a VB6 ActiveX EXE or class-bearing DLL and add it as a reference. The Interop Assembly will be automagically created for you. – Bob Denny Feb 13 '10 at 15:39
  • @ bob denny. Its not always that easy, the VS IDE chooses an option that makes working with complex data structures that have arrays difficult, if not impossible. Its better to use tlbimp unless you have very, very simple inputs and outputs. – Steve Feb 13 '10 at 15:49
  • 1
    @Steve Interesting. Can you give more details about this problem? A link would be useful. – MarkJ Feb 14 '10 at 18:42
3

You can use a compiled VB6 dll in a C# program by using COM Interop.

https://stackoverflow.com/questions/tagged/interop

Community
  • 1
  • 1
Jason
  • 86,222
  • 15
  • 131
  • 146
3

As @Wayne states in his post (+1) it is absolutely possible.

I would go for a rewrite of your VB6 class:
If you have the VB6 source and the funding, I would recommend you to rewrite the class in C#.
Although VB6 may live forever :
Current support Statement for Visual Basic 6.0

Community
  • 1
  • 1
Kb.
  • 7,240
  • 13
  • 56
  • 75
  • I'm confused why people are voting this up, yet gave @sashaeve net -5 for an equivalent answer. – Ben Voigt Sep 03 '11 at 03:53
  • @Kb: It's on this page, but you need a lot of reputation to see deleted answers. He said: "You have to convert it to VB.NET class and than [sic] it is possible to use this code in your C# application". – Ben Voigt Sep 11 '11 at 20:53
0

Sure, you just need to make it a COM object.

Otávio Décio
  • 73,752
  • 17
  • 161
  • 228
  • DLL's created with VB6 are always (well, almost always) COM DLL's. To make them otherwise, you have to go through a lot of black art type hoops. – BobRodes Apr 13 '12 at 19:41