w0051977
w0051977

Reputation: 15807

.NET using a VB6 COM component

I have an ASP.NET application and I want to use a VB6 component. I know that I have to use the ASPCOMPAT tag. Is there anything that needs to be done to the VB6 code to make it thread safe?

I have run some tests and it seems to work perfectly, however I have read comments on here about developers that have run into problems, but the comments are not elaborated. Is there anything that needs to be done to the VB6 code to ensure that it is thread safe? It seems too straightforward. Also I have placed the ASPCONFIG tag on one page only - the page that uses the COM component.

I have imported the component in Visual Studio using the tlbimport tool, which places a .NETwrapper around the COM object.

Upvotes: 0

Views: 267

Answers (1)

David W
David W

Reputation: 10184

The thread safety of VB6 code depends largely on how it was written. A special "subset" of COM was written to conceal most of the hard plumbing involved in COM-based development in the VB6 days, and part of what was concealed was thread management (Multi-threaded apartments, single-threaded apartments, etc) and the VB6 runtime handled threading under the hood. As a result, if you followed the rules, thread safety was more or less taken care of for you.

In most cases, if you attempted to delve into independent thread management, eg calling Windows API functions to create threads outside the VB6/COM "sandbox," then you were playing with fire, and no amount of protection from the .NET side will make it "thread safe." Doing so broke all the internal thread management/marshalling/etc code that VB6 purposely tried to hide. That's pretty much the essence of the difference between the unmanaged (VB6/COM) and managed code (.NET) worlds.

Hope that helps.

Upvotes: 1

Related Questions