The file "pointer.h (sourceforge.net)" contains pointer types that have since been obsoleted by the C++ standard library and the Windows SDK by more robust smart pointers. My experimental branch Owlet had already removed all the pointer types in this file, except for TComRef, which in [r8666] was moved to "shellitm.h (sourceforge.net)", where it is used, allowing "pointer.h" to be removed altogether.
Replacing TComRef with Microsoft::WRL::ComPtr
In "shellitm.h", TComRef is used as a COM smart pointer and also (unadvisedly) as a base class for encapsulation of Shell interfaces. For example:
//
/// Wraps the shell's IMalloc interface.
/// Default constructor obtains shell's IMalloc interface.
/// TComRef<IMalloc> and copy constructors supplied.
/// TComRef<IMalloc> and TShellMalloc assignment operators also supplied.
//
class TShellMalloc: public TComRef<IMalloc>
{
public:
TShellMalloc();
explicit TShellMalloc(const TComRef<IMalloc>& source);
TShellMalloc(const TShellMalloc& source);
TShellMalloc& operator = (const TComRef<IMalloc>& source);
TShellMalloc& operator = (const TShellMalloc& source);
};
The constructor implementation in "shellitm.cpp (sourceforge.net)" retrieves the interface and initialises the pointer:
TShellMalloc::TShellMalloc()
{
HRESULT hr = SHGetMalloc(*this);
TXShell::Check(hr, "SHGetMalloc failed");
}
In Owlet, I now plan to replace TComRef by Microsoft::WRL::ComPtr and simplify the Shell encapsulation by removing these wrapper classes, using a simple using-declaration and a free-standing factory function instead:
template <class T>
using TComPtr = Microsoft::WRL::ComPtr<T>;
using TShellMallocPtr = TComPtr<IMalloc>;
inline auto GetShellMalloc() -> TShellMallocPtr
{
auto m = TShellMallocPtr{};
const auto hr = SHGetMalloc(m.GetAddressOf());
TXShell::Check(hr, "SHGetMalloc failed");
return m;
}
Applicability to the trunk
If there is interest in further modernisation on the trunk (currently OWLNext 8), the same approach can be adopted. If there is demand for backwards compatibility, the wrapper classes can be retained (but deprecated):
//
/// Wraps the shell's IMalloc interface.
/// Default constructor obtains shell's IMalloc interface.
/// \deprecated Use \ref GetShellMalloc instead.
//
class [[deprecated]] TShellMalloc: public TShellMallocPtr
{
public:
TShellMalloc() : TShellMallocPtr{GetShellMalloc()} {}
operator IMalloc*() {return Get();}
operator IMalloc**() { return ReleaseAndGetAddressOf(); }
};
Note that WRL is since Windows 8 now part of the Windows SDK, so no further library dependencies are necessary, provided the minimum Windows version requirement is raised accordingly. The Windows API target version should then also be set to version 8. Currently, OWLNext 7 and 8 target Windows API version 6 (Vista).
Request for feedback
Please let me know whether there is interest in this modernisation effort, and whether you see any compatibility or architectural concerns.
Anonymous
I think it is a good idea to obsolete the non-standard pointers and push users towards using unique_ptr and shared_ptr.
@jogybl wrote:
OK! If you want to take on the work on updating the trunk, see the log for "pointer.h" (sourceforge.net) on the Owlet branch for changes made to eliminate the pointers, especially [r2158], and/or use SVN Blame.
I will commit my replacement of TComRef in "shellitm.h" soon, hopefully, for review and test.
Edit: The proposed refactor was performed in [r8667], deprecating the interface wrappers previously based on TComRef, suitable for compatibility on the trunk. For Owlet, which has no need for this compatibility, I then removed these wrappers in [r8668]. Inheritance from COM smart pointers was eliminated in [r8669] and the documentation and code cleaned up in [r8670] to [r8675]. A regression was fixed in [r8676].
Related
Commit: [r2158]
Commit: [r8667]
Commit: [r8668]
Commit: [r8669]
Commit: [r8670]
Commit: [r8675]
Commit: [r8676]
Last edit: Vidar Hasfjord 2026-03-17
Hi @jogybl, good work on your recent commits on this!
I have not reviewed and tested — I've just browsed the revisions — but it is good to see the OWLNext code move closer to modern C++. This makes it easier to merge between OWLNext and Owlet. Thanks!