473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Using COM within .NET

I have a very simple COM object that I want to use within .NET. The COM
object was written in C++/ATL. The object works but the problem is the
COM object never seems to be released and the DLL files can never be
overwritten without restarting the computer.

MyLibrary.CMyCOMClass netWrappedCOMObj = new MyLibrary.CMyCOMClassClass();
try {
// Currently, not using the object, just create/dispose
} finally {
System.IntPtr unknownInterface =
Marshal.GetIUnknownForObject(netWrappedCOMObj);
while
(System.Runtime.InteropServices.Marshal.Release(un knownInterface) > 0);
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(netWrappedCOMObj)
0);

netWrappedCOMObj = null;
GC.Collect();
GC.WaitForPendingFinalizers();

// I set a breakpoint here and I can't overwrite the COM DLL file. Why
not?
bool debug = true;
}
Nov 17 '05 #1
2 905
"Tommy Vercetti" <ve*********@hotmail.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
I have a very simple COM object that I want to use within .NET. The COM
object was written in C++/ATL. The object works but the problem is the COM
object never seems to be released and the DLL files can never be
overwritten without restarting the computer.
Presumably stopping your .NET application will release the DLL without
rebooting...

MyLibrary.CMyCOMClass netWrappedCOMObj = new MyLibrary.CMyCOMClassClass();
try { // Currently, not using the object, just create/dispose
} finally {
System.IntPtr unknownInterface =
Marshal.GetIUnknownForObject(netWrappedCOMObj);
while (System.Runtime.InteropServices.Marshal.Release(un knownInterface) >
0);
while
(System.Runtime.InteropServices.Marshal.ReleaseCom Object(netWrappedCOMObj)
0);

netWrappedCOMObj = null;
GC.Collect();
GC.WaitForPendingFinalizers();

// I set a breakpoint here and I can't overwrite the COM DLL file. Why
not?
bool debug = true;
}


Releasing all references to an object doesn't unload the DLL. You need to
call (directly or indirectly) CoFreeUnusedLibraries() to get the DLL
unloaded. This is no different in .NET than in native COM development.

-cd
Nov 17 '05 #2
> Presumably stopping your .NET application will release the DLL without
rebooting...
yes.
Releasing all references to an object doesn't unload the DLL. You need to
call (directly or indirectly) CoFreeUnusedLibraries() to get the DLL
unloaded. This is no different in .NET than in native COM development.


I suspected that. Thank you very much!

Do you happen to know the .NET way to invoke CoFreeUnusedLibraries()?
Nov 17 '05 #3

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

Similar topics

4
by: Kathryn | last post by:
I hope you can help as this is driving me crazy! I have an asp which has 3 frames on it as follows: <FRAMESET rows="50%,*,10%"> <FRAME src="rundetailstop.asp" name="rundetailstop"...
1
by: Jay Sartoris | last post by:
Hi, I'm adding a node to my XML document using DOM. When I serialize it, I lose my comments that are above my root node. I've created an OutputFormat obect and set the setOmitComments(false)...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
11
by: Mark Schneider | last post by:
I'm trying to avoid using <table> for formatting purposes where other, reasonable means exist. I'm stuck trying to find a way to find an equivalent for the code below. <table align="center">...
3
by: Pranav Shah | last post by:
What is the differrence between using the "using" caluse outside of the namespace definition and inside the namespace. Example Outside: using System; namespace Example.Outside { }
2
by: josh | last post by:
Hi, I am trying to validate cXML documents against cXML.dtd using the XmlValidatingReader. If I set the XMLValidatingReader's ValidatingType to ValidationType.DTD, I get the following...
1
by: mailsatk | last post by:
Hello people! I am trying to do something that I don't know if anyone else might have tried before...I am writing a Macro in Excel that will give a user the list of all the folders present within...
7
by: Jim in Arizona | last post by:
I'm brand new at ajax. In fact, about 20 minutes ago was the first time I got it to work. The problem I'm having on another page did not work, however. I'm running into the following error: ...
2
by: Taras_96 | last post by:
Hi everyone, I'm trying to run a number of commands stored within a sql file from within php using mysqli::query. The syntax I'm using is: source C:\data\projects\forum...
15
by: r0g | last post by:
Hi There, I know you can use eval to dynamically generate the name of a function you may want to call. Can it (or some equivalent method) also be used to do the same thing for the variables of a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.