質問

I'm new member of the team and I read code below. I wonder do I need to call SafeArrayUnLock in the dctor? I tried to search on web without clear clue. So really appreciate your help!

Code:

class Trasaction
{
private:
    CComSafeArray m_saCache;
public:
    //ctor
    Transaction(CComQIPtr<Reader>& pReader)
    {
        //This call need a SAFEARRAY** as its 3rd parameter
        pReader->ReadData(start, size, &m_saCache);
        SafeArrayLock(m_saCache.m_psa);
    }

};
役に立ちましたか?

解決

As you are holding the SAFEARRAY object through CComSafeArray (an RIIA) class which keeps the SafeArray in locked state - and as you are modifying the pointer directly instead of calling Attach method you have to explicitly call the SafeArrayLock. But you do not have to call unLock in the destructor because the destructor of the CComSafeArray would do the Unlock.

To avoid raising further doubts in the future about the spurious call to SafeArrayLock and a missing SafeArrayUnLock - I suggest to use the Attach method of CComSafeArray by taking the return value first in a plain SAFEARRAY*.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top