473,466 Members | 1,413 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Ensuring a COM object has been released.

I'm writing a little app to search a computer for all revisions of a
COM object and clean them up. All I'm requiring from the user is the
ProgID of one public class in the library.

The app works great but I want to make make sure that the ProgID
entered is valid, so I wrote a simple function to make sure that this
object can be instantiated (code below).

The problem is that I cannot delete the DLL if I use this test because
I get the following error:
Access to the path "C:\WINDOWS\Downloaded Program
Files\CONFLICT.15\ClientUtilities.dll" is denied.

However, if I do not test and simple run the process, then I can
remove the DLL and, in this case, the 'Conflict.15' folder too.

This leads be to believe that the COM object is not being properly
released so that the DLL can be unloaded from memory and, therefore,
the DLL is locked when I try to delete it.

Any ideas?
Public Function TestCOMObject(ByVal ProgID As String) As Boolean
Try
Dim lcTest As Object
Dim TheType As Type
TheType = Type.GetTypeFromProgID(ProgID, True)
lcTest = CreateObject(ProgID)
If Not IsNothing(lcTest) Then
If (TheType.IsCOMObject) Then
Do While
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(lcTest) > 0)
Loop
End If
End If
lcTest = Nothing

Return True
Catch ex As Exception
Return False
Finally
GC.Collect()
GC.WaitForPendingFinalizers()
End Try
End Function

Nov 21 '05 #1
3 1147
Jason,
The app works great but I want to make make sure that the ProgID
entered is valid, so I wrote a simple function to make sure that this
object can be instantiated (code below).
Wouldn't it be easier to just look in the Registry?

Any ideas?


You can try calling the CoFreeUnusedLibraries API.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 21 '05 #2
On Thu, 13 Jan 2005 23:11:22 +0100, Mattias Sjögren
<ma********************@mvps.org> wrote:
Jason,
The app works great but I want to make make sure that the ProgID
entered is valid, so I wrote a simple function to make sure that this
object can be instantiated (code below).
Wouldn't it be easier to just look in the Registry?


I don't just want to know if the ProgID can be found in the registry,
though thanks for the suggstion, I also want to know if it can be
instantiated (all external dependencies exist and such.)
Any ideas?


You can try calling the CoFreeUnusedLibraries API.


Excellent idea! Thanks a ton.


Mattias


Nov 21 '05 #3
That worked. Thanks!

If anyone else is reading and cares about more info on the solution,
the simple declare for this API is:

Public Declare Sub CoFreeUnusedLibraries Lib "ole32.dll" ()

-Jason
You can try calling the CoFreeUnusedLibraries API.

Mattias


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: MuZZy | last post by:
Hi, Lately i've been (and still am) fixing some memory leaks problems in the project i just took over when i got this new job. Among the other issues i've noticed that for localy created objects...
18
by: techie | last post by:
I have a VC++ client that creates a COM object that is implemented in C#. The problem is the COM object doesn't get released, so I get a memory leak. I have no problems creating the COM object...
5
by: david.kao | last post by:
Hi All: I am creating a COM+ Pool object in C#. I set up the following attributes: JIT (true),Pool size; and at the end of each public method I called ContextUtil.DeactivateOnReturn=true to set...
7
by: Lev | last post by:
Hi, I have an unmanaged pointer to a class that I want to hold in a managed class. I pass the pointer (from unmanaged code) in the constructor of the managed class, and at that point it has...
12
by: Bernie Yaeger | last post by:
I use a 3rd party grid throughout my apps. My customers are losing memory each time they open one of the grids. I call me.c1truedbgrid.dispose() each time the window closes, but the memory is...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
35
by: Jamey Shuemaker | last post by:
I've seen multiple threads (several in the last 6 months or so) on this topic, but I wanted to clarify my practices. I understand the need for cleaning object variables by setting them to Nothing...
4
by: Michael Maes | last post by:
Hi, On closing our App, we get following 'InvalidComObjectException': "COM object that has been separated from its underlying RCW cannot be used" The App has been upgraded from .Net1.1 to...
2
by: Ivor Somerset | last post by:
Hello, In my ASP code I sometimes write functions that return an object (generally an XML node). Such a function is invoked this way: Set Object1 = MyFunction(SomeValue) And at the end of...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.