3,245
社区成员
发帖
与我相关
我的任务
分享
template<class T>
class CBSTR
{
protected:
BSTR bstr;
T* pT;
public:
CBSTR() : bstr(NULL), pT(NULL) {}
CBSTR(const T& other)
{
bstr = ::SysAllocStringByteLen((char*)&other, sizeof(T));
pT = &other;
}
CBSTR(BSTR obstr)
{
bstr = obstr;
pT = (T*)obstr;
}
~CBSTR()
{
if (bstr)
{
::SysFreeString(bstr);
bstr = NULL;
}
pT = NULL;
}
operator BSTR() { return bstr; }
operator T*() { return pT; }
};
CBSTR<EDPoint> bstred(empPoint);
pInterface->MethodIn((BSTR)bstred, ...);
BSTR outbstr = NULL;
pInterface->MethodOut(&outbstr);
CBSTR<EDPoint> bstred2(outbstr);
EdPoint* pedp = bstred2;
pedp->x;
pedp->y;