object used to convert a pointer to a c string
Hi,
I would like to write some helper function to convert some pointer
pointing to a whchar_t*(windows unicode) to a standard utf8 string.
Here is the code I currently have :
void*
OS_GDAbItem_GetProperty(GDAbItem* gpContact, EAbItemProp eAbPropId)
{
ErrorCode err;
void* pRet = NULL;
CEPROPVAL *lpProp;
GDPropVal* gynPropVal = NULL;
err = GDAbItem_GetPropertyEx(gpContact, eAbPropId, &gynPropVal);
if (err == 0)
{
lpProp = (CEPROPVAL *) gynPropVal->pOsPropVal;
if (lpProp->wFlags != CEDB_PROPNOTFOUND)
{
switch( gynPropVal->ulPropType )
{
case CEVT_LPWSTR:
{
pRet = lpProp->val.lpwstr ;
#ifndef _UNICODE
// HERE I SHOULD convert val.lpwstr to a // utf8 string and
then deallocate // original string
#endif
break;
}
case CEVT_FILETIME:
{
pRet = &(lpProp->val.filetime)
;break;
}
}
}
}
return pRet
}
I would like to avoid to put #ifndef everywhere in my code, that's why I
wanted to make a simple class that would do the ugly job.
Actually the pointer I am interested in is a void* ie it can point to
anything BUT in the case I am assigning from a windows unicode string
(const wchar_t*) I want to do some specific action(convert into utf8).
So I am starting with this :
template <typename T>
class IConvPtr
{
public:
IConvPtr& IConvPtr::operator=(T* aptr)
{
m_ptr = aptr;
}
inline void* getPtr() { return m_ptr; }
private:
void* m_ptr;
};
But not sure this is a right way of doing it. So to sum up as long as
assigned pointer is not a const wchar_t* I just copy pointer otherwise I
do some action.