Using VB6 objects from .NET

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi

I have some old VB6 code and I need to automate some testing from .NET by using the VB6 objects and interrogating the results. The VB6 object basically just does some work and returns an XML string which I need to validate

An asp page using the VB6 object would be something like..

set myObj = CreateObject("MyAPI.SomeVB6Class"
result = myObj.DoSomething(

Can anyone advise me of the best approach to doing this through .NET? Can I instantiate and use the VB6 objects? Or do I have to use asp.net page and then interrogate that

Many thanks...
 
Hi,

From your description ,you'd like to use VB6 created COM object in .NET
application, yes?

There are two means to call COM object in .NET:
1. still use t he CreateObject to create a COM object via its name, and
then call its method. But this will be very complex if we are using the C#,
we need to call the created COM object's method by "invoke". If you are
using VB.NET, it's ok to directly call any methods on the object since
VB.NET use laterbinding and check the method at runtime.

2. Another way is use the Interopservcie to generate a .NET wrapper class
for the COM object. Thus, the COM object are encapsulated by the Wrapper
class and can be called in .NET as a dotnet class. Such as using "new"
constructor and have intellisence help in IDE. I recommend that you call
the COM object via this way. Here are some tutorial and reference on using
COM Interop to Expose COM component to .NET:

#Exposing COM Components to the .NET Framework
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconExposingCOMCompone
ntsToNETFramework.asp?frame=true

#COM Wrappers
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconCOMWrappers.asp?fr
ame=true

Hope helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Many thanks. Second option sounds like the way to go, and thanks for the tutorial links

I did wonder if I'd be able to just instantiate an aspx page from C#, have that call my object using VBScript, and then interrogate the contents of the page. Is this not possible?
 
Hi,

This time I'm afraid not possible to do so. As I mentioned in the last
reply, in dotnet we can generate a dotnet wrapper class to encapsulated all
the COM object's interfaces into the wrapper class. Then, we call the
wrapper class in dotnet code(managed code). And in ASP.NET page, we use
dotnet language as serverside programming language, for example: C#, VB.NET
JSCRIPT.NET .. but not vbscript, the vbscript is the original one used
serverside script in classic ASP. In other word, using vbscript to call COM
in asp page is the same as using vb to call COM in vb application. In
dotnet, we use the managed code (dotnet language). How do you think of
this? If you have anything unclear, please feel free to let me know. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
 
Thanks I have used your suggestion and added a COM reference to the project. It works fine!
 
Back
Top