我有一个共同点,在C++实施。 我正在使用VB6申请中的这个物体。
The question is how to implement a methods that get and return a pointer to an interface. Here is the sample of an IDL:
[...]
interface ICOMCvDC : IUnknown
{
HRESULT GetPen([retval][out] ICOMCvPen** ppPen);
HRESULT SetPen([in] ICOMCvPen* pPen);
};
下面是部件类别物体的kel:
class COMCvDC : public ICOMCvDC
{
public:
...
STDMETHODDECL GetPen(
/* [retval][out] */ ICOMCvPen** ppPen);
STDMETHODDECL SetPen(
/* [in] */ ICOMCvPen* pPen);
...
protected:
ICOMCvPen* m_pen;
};
...
STDMETHODIMP COMCvDC::GetPen(
/* [retval][out] */ ICOMCvPen** ppPen)
{
*ppPen = m_pen;
return S_OK;
}
STDMETHODIMP COMCvDC::SetPen(
/* [in] */ ICOMCvPen* pPen)
{
m_pen = pPen;
return S_OK;
}
我是执委会的开端人,因此,如果我这样做是正确的,我就不放心。 我感到,我需要使用<条码>中某些接口器的QueryInterface方法。 了解VB6在解释守则时正在做些什么也是令人感兴趣的:
Dim pen1 As ICOMCvPen
Set pen1 = dc1.GetPen()
它是否将<代码>AddRef方法称作通过<代码>GetPen方法回归的接口点?
Update 1
我已实施了两个试验目标(COMCv 和COMCv 试验场),这些试验目标只是标出所有所谓的方法。 接着,我执行以下VB6法典:
Dim test1 As ICOMCvTest
Set test1 = New COMCvTest
Debug.Print "Ref: " & test1.GetReferenceCounter
Set test1 = Nothing
以下是这些物体生命周期的标志:
COMCvTestFactory::COMCvTestFactory(); m_cRef = 1
COMCvTestFactory::QueryInterface() --- begin ---
IID is {00000001-0000-0000-C000-000000000046}
IID is IID_IClassFactory
COMCvTestFactory::AddRef(); m_cRef = 2 (was 1)
COMCvTestFactory::QueryInterface() ---- end ----
COMCvTestFactory::Release(); m_cRef = 1 (was 2)
COMCvTestFactory::CreateInstance() --- begin ---
COMCvTest::COMCvTest(); m_cRef = 1
COMCvTest::QueryInterface() --- begin ---
IID is {00000000-0000-0000-C000-000000000046}
IID is IID_IUnknown
COMCvTest::AddRef(); m_cRef = 2 (was 1)
COMCvTest::QueryInterface() ---- end ----
COMCvTest::Release(); m_cRef = 1 (was 2)
COMCvTestFactory::CreateInstance() ---- end ----
COMCvTest::AddRef(); m_cRef = 2 (was 1)
COMCvTest::Release(); m_cRef = 1 (was 2)
COMCvTestFactory::Release(); m_cRef = 0 (was 1); deleting object
COMCvTestFactory::~COMCvTestFactory()
COMCvTest::QueryInterface() --- begin ---
IID is {00000000-0000-0000-C000-000000000046}
IID is IID_IUnknown
COMCvTest::AddRef(); m_cRef = 2 (was 1)
COMCvTest::QueryInterface() ---- end ----
COMCvTest::QueryInterface() --- begin ---
IID is {9F660698-1950-4DE8-BB5F-C8D2D61F7367}
IID is IID_ICOMCvTest
COMCvTest::AddRef(); m_cRef = 3 (was 2)
COMCvTest::QueryInterface() ---- end ----
COMCvTest::QueryInterface() --- begin ---
IID is {7FD52380-4E07-101B-AE2D-08002B2EC713}
IID is IID_IPersistStreamInit
COMCvTest::QueryInterface() --- begin ---
IID is {37D84F60-42CB-11CE-8135-00AA004BB851}
IID is IID_IPersistPropertyBag
COMCvTest::Release(); m_cRef = 2 (was 3)
COMCvTest::Release(); m_cRef = 1 (was 2)
COMCvTest::GetReferenceCounter; m_cRef = 1
COMCvTest::Release(); m_cRef = 0 (was 1); deleting object
COMCvTest::~COMCvTest()
如同VB6一样,它试图查询IPersistStreamInit
和IPersistPropertyBag
来自COM标的接口。 为什么? 另外,我不理解为什么在查询<代码>ICOMCv《<<<<<>>>>> 代码>接口之前出现查询?