How can I unload a COM DLL?

S

spacejay

I'm programming an VB.NET application wich is using a third-party
COM-DLL-module. The Module is only loaded if needed.
And now my problem: My Application doesn't end correct and hang up
itself. After I have closed my application, i can see in the task
manager a CPU Load about over 95%. I could verify that this only
happens, if the COM Module was used by my application. If the Module
wasn't used then my application ends correct.
With an extendend Taskmanager I could unload manual single DLL's which
an application is using. And if I unload the COM Module DLL manual, so
my application ends correct.

Now my question: Is it possible (and how) to unload a DLL, which my
application has loaded dircet by vb code?

I'm very thankfully for every of your answers.

Greets

Jan



--------Example---------

'The Definition of the COM-Module
Private m_FaktNT As FaktNT.OLESrv

....

'If I need the COM-Module, I make a new Instance of the COM-Module
m_FaktNT = New FaktNT.OLESrv()

....

'Now I can use the Interfaces of the Module
m_FaktNT.AdrdGetName()
m_FaktNT.AdrdGetField()

....

'At the end of my application I release the COM-Object from my
application
While Marshal.ReleaseComObject(m_FaktNT) >= 0
End While
'And set set the Reference to Nothing
m_FaktNT = Nothing
 
M

Mike McIntyre [MVP]

SpaceJay,

Check out the System.Runtime.InteropServices.Marshal namespace and specifically the ReleaseComMethod method.
 
S

Shawn B.

I simply put the following code in a common class somewhere, import in the
namespace, and call "Release([ComObjectReferenceName])"


-----------------
Imports System.Runtime.InteropServices
Imports System.Runtime.InteropServices.Marshal
..
..
..
Public Shared Function Release(ByRef ComObject As Object) As Integer
Return Release(ComObject, False)
End Function

Public Shared Function Release(ByRef ComObject As Object, ByVal collect As
Boolean) As Integer
Dim Result As Integer

Try
Result = ReleaseComObject(ComObject)
ComObject = Nothing

If (collect) Then
GC.Collect()
GC.WaitForPendingFinalizers()
End If

Catch
End Try

Return Result
End Function


SpaceJay,

Check out the System.Runtime.InteropServices.Marshal namespace and
specifically the ReleaseComMethod method.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top