Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

exposing vb6 modules to .Net code

Status
Not open for further replies.

mcs1000

Programmer
Jul 3, 2007
26
0
0
GB
I am trying to use COM interop to include some legacy code.

I have managed to use functions from vb6 classes.

How can I use functions from vb6 modules?
 
Maybe someone will come back with a different answer, but in my experience you can't.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
COM objects need to be registered and instansiated which are supported (I think) in .NET but I don't see where the Modules come in to the equation.

Are you talking about a DLL? If so you may want to look at:
<DllImport("yourdll.dll", EntryPoint:="?is_binary@@YA_NXZ", SetLastError:=True, CharSet:=CharSet.Ansi, ExactSpelling:=True, CallingConvention:=CallingConvention.Cdecl)> _
Public Function IsBinary() As Boolean
End Function

This is an import from a cdecl DLL with decorated functions but since I'm not 100% sure what you need...
--

woogoo
 
i'm trying to wrap some existing code in vb6 to use in c#.

I've extracted most of the code into a dll.

I really have a lot of legacy code so I don't want to convert (vb6) modules into (vb6) classes because I am trying to minimise conversion costs.

Either way thanks for your ideas
 
Code:
i'm trying to wrap some existing code in vb6 to use in c#.

I've extracted most of the code into a dll.

I really have a lot of legacy code so I don't want to convert (vb6) modules into (vb6) classes because I am trying to minimise conversion costs.

Either way thanks for your ideas
Ok, I'm just going to say this. If I have misunderstood or if any of this is obvious then sorry.

Take this also with minimal use of VB6 as I've done mostly VBA and VB.net. A module in and of itself is nothing more than a container for code. When it is compiled in a program it is nothing more than another piece of code in that program. Someone once told me that actually in VB6 it is converted into a Shared Class, but it is still a part of the program. Either way the code is dependent on that compiler. You can't just import it without changes.

Now then if it is all in a precompiled dll then yes you can use it from C#. You would want to ask in the C# forum how to use it. If you mean you have stuff left over that isn't in a dll then you are going to have to do something to it. Either compile it how ever to make it a dll in VB6 or recode it in C#. If you don't know enough C# then try coding it to vb.net and make it into a dll to use in C#. The code wizard may be able to convert it all. If there is anything left over it may be close enough to figure out or we may be able to help you.

-I hate Microsoft!
-Forever and always forward.
-My kingdom for a edit button!
 
Sorwen, you've heard correctl :). The module files are simply a place to put global settings. If you have a lot of functions within the module, just copy and paste them all into a new class and then debug. You'll have to go through and figure out what is using the "global" variables, and how it gets assigned manually to make sure that you don't get bad data.

Personally, I would bite the bullet now and fix it properly. If you just wrap the code, you'll make it more complicated to debug in the future. It might mean you have to work late a few nights (depending on how much is there), but in the end, converting the modules to a .Net assembly will save you a ton of headaches when it's time to debug.

im in ur stakz, overflowin ur heapz!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top