A number of people have asked me questions like “can I quote your blog in my blog?”, “can I post your article in my wiki?”, “can I use this information in my MSDN Magazine article?” and so on. It is nice of you to ask, particularly since there is practically nothing I can do to…
Tag: Pages
deque.cs
public interface IDeque<T> { T PeekLeft(); T PeekRight(); IDeque<T> EnqueueLeft(T value); IDeque<T> EnqueueRight(T value); IDeque<T> DequeueLeft(); IDeque<T> DequeueRight(); bool IsEmpty { get; } } public sealed class Deque<T> : IDeque<T> { private sealed class EmptyDeque : IDeque<T> { public bool IsEmpty { get { return true; } } public IDeque<T> EnqueueLeft(T value) { return new SingleDeque(value); } …
Original: When Are You Required To Set Objects To Nothing?
NOTE: I have significantly revised this article. What you are reading now is the archive of the original posting. The updated version is here http://blogs.msdn.com/ericlippert/archive/2004/04/28/122259.aspx It’s getting into sailing/kite flying season in Seattle — that is, it’s light out after work again — and my home dev machine is presently busted (bad hard disk,…
invoke.cpp
#include “headers.h” HRESULT InvokeDispatch(IDispatch * pdisp, DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS * pDispParams, VARIANT * pvarResult, EXCEPINFO * pExcepInfo, UINT * pError){ AssertReadPtr(pdisp); HRESULT hr; // We must addref the pointer before the invocation. Why? Consider // this scenario: the invocation calls a method which calls back // into…
invoke.h
#ifndef INVOKE_H // {#define INVOKE_H extern HRESULT InvokeDispatch(IDispatch * pdisp, DISPID dispid, REFIID riid, LCID lcid, WORD flags, DISPPARAMS * pDispParams, VARIANT * pvarResult, EXCEPINFO * pExcepInfo, UINT * pError); extern BOOL IsValidDispatch(VARIANT * pvar); #endif // INVOKE_H }
binder.cpp
#include “headers.h” Binder::Binder(){ DLLAddRef(); this->m_cref = 1; this->m_thread = GetCurrentThreadId();} Binder::~Binder(void){ DLLRelease();} HRESULT Binder::Create(Binder * * ppBinder){ AssertOutPtr(ppBinder); *ppBinder = new Binder(); if (NULL == *ppBinder) return E_OUTOFMEMORY; return S_OK;} // IUnknown STDMETHODIMP_(ULONG) Binder::AddRef(void){ return InterlockedIncrement(&this->m_cref);} STDMETHODIMP_(ULONG) Binder::Release(void){ long cref = InterlockedDecrement(&this->m_cref); if (0 == cref) delete this; return cref;} STDMETHODIMP Binder::QueryInterface(REFIID riid,…
binder.h
#ifndef BINDER_H // {#define BINDER_H class Binder : public IDispatch{ protected: class Name { public: Name(); ~Name(); HRESULT SetValue(VARIANTARG * pvar); HRESULT GetValue(VARIANT * pvar); BOOL IsFunction(void); HRESULT ExecuteFunction(UINT cArgs, VARIANTARG * rgvarArgs, VARIANT * pvarResult); VARIANT m_var; }; public: static HRESULT Create(Binder * * ppBinder); // IUnknown STDMETHOD(QueryInterface)(REFIID…
nameditemlist.h
#ifndef NAMEDITEMLIST_H // {#define NAMEDITEMLIST_H class NamedItemList{ private: class NamedItem { private: NamedItem(); public: ~NamedItem(); static HRESULT Create(const WCHAR * pszName, NamedItem * * ppNamedItem); NamedItem * m_pNext; BSTR m_bstrName; DWORD m_flags; BOOL IsPersistent(); void Reset(); }; NamedItemList(); NamedItem * Find(const WCHAR * psz); Mutex * m_pMutex; …
nameditemlist.cpp
#include “headers.h” NamedItemList::NamedItemList(){ this->m_cBuckets = 0; this->m_Buckets = NULL; this->m_pMutex = NULL;} NamedItemList::~NamedItemList(){ this->Clear(); if (NULL != this->m_Buckets) delete[] this->m_Buckets; if (NULL != this->m_pMutex) delete this->m_pMutex;} HRESULT NamedItemList::Create(int cBuckets, NamedItemList * * ppNamedItemList){ AssertOutPtr(ppNamedItemList); Assert(cBuckets > 0); HRESULT hr; int iBucket; NamedItemList * pNamedItemList = NULL; *ppNamedItemList = NULL; pNamedItemList = new…
mutex.cpp
#include “headers.h” Mutex::Mutex(){ m_fInitialized = FALSE;} HRESULT Mutex::Create(Mutex * * ppMutex){ AssertOutPtr(ppMutex); HRESULT hr; BOOL fSuccess; DWORD error; Mutex * pMutex = NULL; pMutex = new Mutex(); if (NULL == pMutex) { hr = E_OUTOFMEMORY; goto LError; } fSuccess = InitializeCriticalSectionAndSpinCount(&pMutex->m_criticalsection, 0); if (!fSuccess) { error = GetLastError(); hr = HRESULT_FROM_WIN32(error); goto…