1

Excluding STL, I only found CComPtr in C++ windows programming. Is there any other types of smart pointers in windows SDK? Thanks.

3
  • CComPtr is an equivalent of STL's counted_ptr. Is there in windows api the equivalent of STL's copied_ptr, owned_ptr, linked_ptr, cow_ptr? Commented Apr 17, 2011 at 1:28
  • 2
    The C++ STL does not have anything called counter_ptr. It does have auto_ptr, which is not counted. Commented Apr 17, 2011 at 1:29
  • 1
    (stating the obvious) tr1, on the other hand, has a counted pointer named shared_ptr Commented Apr 18, 2011 at 16:33

3 Answers 3

1

First, STL's and boost's smart pointers are available on Windows and there's nothing wrong with using those.

Speaking of purely Windows stuff, COM interface pointers, with their AddRef/Release lifetime management model, readily lends itself to smart pointers. There are some smart pointer classes in Windows-specific libraries that are geared towards storing COM interface pointers. In addition to the ATL's CComPtr<>, there's _com_ptr_t<> of Microsoft Native COM, and MFC's COleDispatchDriver. The latter is hardly ever used with the advent of Native COM. With the exception of CComPtr, those are used together with type library import facilities.

Sign up to request clarification or add additional context in comments.

Comments

1

In the Windows SDK (specific to ATL), there is CAutoPtr(single item allocation) and CAutoVectorPtr (array allocation).

Comments

0

The MSDN article states that CComPtr is designed to be used with COM objects only. Generally Boost smart pointers are commonly used as a platform-independent C++ smart pointer library. Since the concept of smart pointers isn't bound to a particular OS, there's really no need to use a smart pointer implementation bound to Windows, even if that's the only platform you plan on developing the application for.

1 Comment

If you are dealing with COM objects CComPtr makes sense. It uses the COM reference counting, so if you pass the pointer to other code not using the same smart pointer class, that callee can hold a reference. Plus you get the QueryInterface method built in. So in some circumstances it does make sense to use this, provided you're already writing highly non-portable code (say, a Windows GUI...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.