Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Destructors for COM components

Posted on 2004-10-22
2
Medium Priority
?
529 Views
Last Modified: 2013-11-25
Hi,
   I used the ATL COM wizard to create a component. I made an interface IDBManager. The implementation class is CDBManger. This class handles Database Operations. In the constructor of this class I've opened a few connections to databases. I want to release these connections when the component is killed....where do i write the code for that...in the destructor itself? Or anywhere else?
0
Comment
Question by:manoj_johar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Expert Comment

by:andrewjb
ID: 12379342
Destructor will do if you're only diong non-COM related stuff.
0
 

Accepted Solution

by:
Codealot earned 375 total points
ID: 12381150
To do that you can override 'FinalRelease' on the ATL class your class is deriving from. From the ATL Library Reference:

CComObjectRootEx::FinalReleaseSee Also
CComObjectRootEx Overview | Class Members | CComObjectRootEx::FinalConstruct
You can override this method in your derived class to perform any cleanup required for your object.

void FinalRelease( );
Remarks
By default, CComObjectRootEx::FinalRelease does nothing.

Performing cleanup in FinalRelease is preferable to adding code to the destructor of your class since the object is still fully constructed at the point at which FinalRelease is called. This enables you to safely access the methods provided by the most derived class. This is particularly important for freeing any aggregated objects before deletion.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

596 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question