|
-
April 17th, 2012, 09:43 AM
#1
IAutoComplete tutorial
Hi All,
I have been using this tutorial to implement Auto completion in one of my text boxes. However I don't understand what they mean by Implementing IEnumString...
I've looked at this link http://www.codeproject.com/Articles/...-implementatio and they skip the actual reasoning and explanation of the implementation. I guess it is just my unfamiliarity with Interfaces in general. You take a new object (say CCustomAutoComplete) and implement the following functions as (public/private?) functions:
Clone(), Next(), Reset(), Skip()
the question is... how do you know how they are implemented? is each CCustomAutoComplete just a string that links to another CCustomAutoComplete (like a linked list?) Can I use TCHARS?
Thanks for the help.. I'm quite clueless on COM and OOP
MSDN Tutorial:
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
UPDATE:
I've created a skeleton for the new class:
My questions are:
1) am I on the right track here? Am I even defining this class correctly, and do i need more auxiliary functions and members and what not?
2) Is it OK to create the object using a pointer to an array of TCHAR arrays (essentially a TCHAR **)?
3) How does memory allocation work in this case?
4) Do I even need the COM IUnknown implementation if this is just a simple enumString implementation (I don't think IenumString is derived from IUnknown).
I probably have more questions but I can't think of anymore right now. I would also like to stick with a simple TCHAR implementation of this...
Code:
// custom auto complete
class CCustomAutoComplete : public IEnumString
{
private:
// Private members
TCHAR m_CurrList[256][64];
ULONG m_nCurrentElement;
ULONG m_nRefCount;
BOOL m_fBound;
public:
// Constructors/destructors
CCustomAutoComplete()
{
InternalInit();
}
CCustomAutoComplete(TCHAR ** p_ArrayList)
{
InternalInit();
SetList(p_ArrayList);
}
~CCustomAutoComplete()
{
// free array...?
}
public:
// Implementation
BOOL SetList(TCHAR ** p_ArrayList)
{
return TRUE;
}
BOOL AddItem(TCHAR * p_Item)
{
return TRUE;
}
BOOL RemoveItem(TCHAR * p_RemoveItem)
{
return TRUE;
}
BOOL Clear()
{
return TRUE;
}
public:
//
// IUnknown implementation
//
STDMETHODIMP_(ULONG) AddRef()
{
return ::InterlockedIncrement(reinterpret_cast<LONG*>(&m_nRefCount));
}
STDMETHODIMP_(ULONG) Release()
{
ULONG nCount = 0;
nCount = (ULONG) ::InterlockedDecrement(reinterpret_cast<LONG*>(&m_nRefCount));
if (nCount == 0)
delete this;
return nCount;
}
STDMETHODIMP QueryInterface(REFIID riid, void** ppvObject)
{
HRESULT hr = E_NOINTERFACE;
if (ppvObject != NULL)
{
*ppvObject = NULL;
if (IID_IUnknown == riid)
*ppvObject = static_cast<IUnknown*>(this);
if (IID_IEnumString == riid)
*ppvObject = static_cast<IEnumString*>(this);
if (*ppvObject != NULL)
{
hr = S_OK;
((LPUNKNOWN)*ppvObject)->AddRef();
}
}
else
{
hr = E_POINTER;
}
return hr;
}
public:
//
// IEnumString implementation
//
STDMETHODIMP Next(ULONG celt, LPOLESTR* rgelt, ULONG* pceltFetched)
{
return S_OK;
}
STDMETHODIMP Skip(ULONG celt)
{
return S_OK;
}
STDMETHODIMP Reset(void)
{
return S_OK;
}
STDMETHODIMP Clone(IEnumString** ppenum)
{
return S_OK;
}
private:
// Internal implementation
void InternalInit()
{
m_nCurrentElement = 0;
m_nRefCount = 0;
m_fBound = FALSE;
}
};
Last edited by kingting; April 17th, 2012 at 05:15 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|