Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Reg-Free COM for a vb6 dll reference in a .net project?

I've been trying to solve this issue for a long time, and nothing seems to work.

I have a COM DLL written in vb6. I add a reference to this DLL in .net, with the 'isolated' and 'copy local' properties set to true on the reference. Apparently this is supposed to enable reg-free com.

But it doesn't work. If I try on another computer, or unregister the DLL with regsvr32, trying to access the DLL throws an exception (essentially saying the desired com class does not exist). The DLL and manifest files are in the same folder as the EXE, but it apparently just totally ignores them.

What am I doing wrong? I've read a ton of scattered articles about this but none of them give me a working solution. I've tinkered with visual studio to no avail. I've tinkered a small amount with make-my-manifest, but it didn't work (even on a test project).

like image 445
Craig Gidney Avatar asked May 01 '09 15:05

Craig Gidney


3 Answers

I was creating and using the com class on a non-ui thread. Apparently Reg-Free com on vb6 DLLs doesn't work in that situation. This test code shows it:

Private Sub RunTest() Handles Button1.Click
    Try
        Dim x As New RegTestProject.RegTestCall
        MsgBox(x.RegTestFunction())
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Private Sub RunThreadedTest() Handles Button2.Click
    'fails if reg-free COM is used'
    Dim t As New Threading.Thread(AddressOf RunTest)
    t.Start()
End Sub

When I run this with the DLL registered normally, both tests succeed. If I use reg-free com, the threaded test fails even though the normal test still succeeds. Looks like this is going to be a huge pain to work-around.

like image 90
Craig Gidney Avatar answered Oct 31 '22 11:10

Craig Gidney


I'm pretty sure that when you reference COM components in this way, the COM component import happens every time you build. That means that the COM component must be registered the traditional way on every machine the project will be built on.

like image 45
Daniel Pratt Avatar answered Oct 31 '22 11:10

Daniel Pratt


Here's a link that describes using registration free com interop. If you've already done this please post your manifest file. You might have a typo your missing.

Edit

Just a thought might be simpler to just register the dll the first time the app runs on a new machine. Registration free com interopt is only available on Windows XP and newer so if your targeting any dinosaurs out there it won't work.

like image 39
JoshBerke Avatar answered Oct 31 '22 13:10

JoshBerke