Last week at work, I was asked about how one would go about displaying forms that are hosted within a VB6 ActiveX DLL.  The first thing that went through my mind was, “Why would you?” … well, the DLL was “legacy” code that couldn’t be ported to .NET due to time constraints.  So, how do you do it?

Well, if your DLL displays any forms (aka calls the Show method on them), you will throw a COMException.  What’s the COM exception for?  The issue outlined in this KB Article.  Here’s a quick summary of the issue from the KB article:

Modeless forms displayed by in-process components cannot function correctly unless they can communicate with the client's message loop. Therefore, in- process components created with Visual Basic can display modeless forms only in client processes that support such communication.

If you read through the KB article, there’s an answer towards the bottom, you will need to use the vbModal constant as a parameter for the Show method. Here's an example:

If App.NonModalAllowed Then
Form1.Show vbModeless
Form1.Show vbModal

Please note that the “safest way” to get your application up and running, is to have all your code to be managed.  It’s always good to lower the amount of “moving parts” within your application.

Hope this helps you out!