PC Review


Reply
Thread Tools Rate Thread

How can I unload a COM DLL?

 
 
spacejay
Guest
Posts: n/a
 
      13th Apr 2004
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
 
Reply With Quote
 
 
 
 
Mike McIntyre [MVP]
Guest
Posts: n/a
 
      13th Apr 2004
SpaceJay,

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

--
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com


"spacejay" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> 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

 
Reply With Quote
 
Shawn B.
Guest
Posts: n/a
 
      13th Apr 2004
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


"Mike McIntyre [MVP]" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
SpaceJay,

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

--
Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com


"spacejay" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unload Me Jac Tremblay Microsoft Access VBA Modules 0 1st May 2010 02:30 PM
cancel unload event on mainform from subform unload event??? clawdogs@gmail.com Microsoft Access Form Coding 1 28th Apr 2009 04:10 PM
cancel unload event on mainform from subform unload event??? KLZA Microsoft Access Forms 0 27th Apr 2009 09:18 PM
unload Maarten Microsoft VB .NET 4 26th Dec 2004 04:42 PM
unload assembly - AppDomain.Unload does not work as expected =?Utf-8?B?RGllcmsgRHJvdGg=?= Microsoft Dot NET Framework 2 4th Apr 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:12 AM.