Click here to Skip to main content
15,923,909 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: How can i detect the the Program Files Folder Pin
Larsson28-Aug-04 12:51
Larsson28-Aug-04 12:51 
GeneralRe: How can i detect the the Program Files Folder Pin
Michael Dunn28-Aug-04 13:50
sitebuilderMichael Dunn28-Aug-04 13:50 
GeneralParallell processes Pin
delis28-Aug-04 0:56
delis28-Aug-04 0:56 
GeneralRe: Parallell processes Pin
Joaquín M López Muñoz28-Aug-04 9:23
Joaquín M López Muñoz28-Aug-04 9:23 
GeneralRe: Parallell processes Pin
delis29-Aug-04 2:43
delis29-Aug-04 2:43 
GeneralRe: Parallell processes Pin
Joaquín M López Muñoz29-Aug-04 2:47
Joaquín M López Muñoz29-Aug-04 2:47 
QuestionSmart Pointers ?? Pin
zahid_ash28-Aug-04 0:35
zahid_ash28-Aug-04 0:35 
AnswerRe: Smart Pointers ?? Pin
Lim Bio Liong28-Aug-04 7:22
Lim Bio Liong28-Aug-04 7:22 
Hello Zahid,

Smart Pointers are actually objects which wrap around actual memory pointers. These memory pointers usually point to objects which are reference counted.

Smart Pointers are usually bound to these object pointers on construction. During construction, a smart pointer would usually increment the reference count of the pointed-to object. For example

SmartPtr(Interface *& pInterface) :
m_pInterface(pInterface)
{
if (m_pInterface)
{
m_pInterface -> AddRef();
}
}

During destruction, the smart pointer will usually decrement the reference count of pointed-to object. For example :

~SmartPtr()
{
if (m_pInterface)
{
m_pInterface -> Release();
m_pInterface = 0;
}
}

Smart Pointers can also increase the ref count of their internal object pointers when they are assigned to another object. For example :

// Copies and AddRef()'s the interface.
//
SmartPtr& operator=(const SmartPtr& copypointer) throw()
{
if (operator!=(copypointer))
{
Interface* pOldInterface = m_pInterface;

m_pInterface = copypointer.m_pInterface;

if (m_pInterface)
{
m_pInterface -> AddRef();
}

if (pOldInterface)
{
pOldInterface -> Release();
pOldInterface = NULL;
}
}

return *this;
}


It is this automated reference increment and decrement feature of smart pointer objects that make them most useful for keeping the reference count of COM objects (through their interface pointers).

To properly keep track of COM objects (via their interface pointers), AddRef() and Release() calls must tally. Otherwise there will be reference undercount (leading to crashes) and reference overcount (leading to memory leaks). This is precisely what Smart Pointers are designed to overcome.

There are many more useful functionalities behind Smart Pointers. Lookup the definition of _com_ptr_t in MSDN.

Regards,
Bio.



QuestionHow can I hide mouse pointer when it comes over my window Pin
Atif Mushtaq28-Aug-04 0:09
Atif Mushtaq28-Aug-04 0:09 
AnswerRe: How can I hide mouse pointer when it comes over my window Pin
Trollslayer28-Aug-04 2:19
mentorTrollslayer28-Aug-04 2:19 
AnswerRe: How can I hide mouse pointer when it comes over my window Pin
Graham Bradshaw28-Aug-04 2:23
Graham Bradshaw28-Aug-04 2:23 
AnswerRe: How can I hide mouse pointer when it comes over my window Pin
cmk28-Aug-04 11:12
cmk28-Aug-04 11:12 
AnswerRe: How can I hide mouse pointer when it comes over my window Pin
Mika Larramo2-Sep-04 13:04
Mika Larramo2-Sep-04 13:04 
GeneralTooltip for CListBox contents Pin
Raghunandan S27-Aug-04 22:10
Raghunandan S27-Aug-04 22:10 
GeneralRe: Tooltip for CListBox contents Pin
Ivan Cachicatari28-Aug-04 19:06
Ivan Cachicatari28-Aug-04 19:06 
GeneralDetecting HTTP errors with HttpOpenRequest/HttpSendRequest Pin
Michael Dunn27-Aug-04 21:21
sitebuilderMichael Dunn27-Aug-04 21:21 
GeneralReading a bitmap to a 2D array Pin
davidgin12327-Aug-04 20:59
davidgin12327-Aug-04 20:59 
GeneralRe: Reading a bitmap to a 2D array Pin
Vaclav29-Aug-04 8:30
Vaclav29-Aug-04 8:30 
GeneralTable selection Pin
Member 52815527-Aug-04 20:39
Member 52815527-Aug-04 20:39 
Generalms flexgrid Pin
Mike Danberg27-Aug-04 17:13
Mike Danberg27-Aug-04 17:13 
GeneralReadFile and reading a single line of text Pin
Paolo Ponzano27-Aug-04 13:08
Paolo Ponzano27-Aug-04 13:08 
GeneralRe: ReadFile and reading a single line of text Pin
darkbyte27-Aug-04 13:53
darkbyte27-Aug-04 13:53 
GeneralApplication event and messages "sniffer" Pin
27-Aug-04 12:16
suss27-Aug-04 12:16 
GeneralRe: Application event and messages "sniffer" Pin
darkbyte27-Aug-04 13:48
darkbyte27-Aug-04 13:48 
GeneralRe: Application event and messages "sniffer" Pin
Charlie Williams27-Aug-04 14:07
Charlie Williams27-Aug-04 14:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.