CFactoryTemplate::m_lpfnNew member

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Pointer to a function that creates an instance of the object.

Syntax

LPFNNewCOMObject m_lpfnNew;

Remarks

In your DLL, declare a static function that returns a pointer to a new instance of the object. In the factory template, set the m_lpfnNew member variable to the address of this static function.

The function pointer type is LPFNNewCOMObject.

The following example shows a typical function for m_lpfnNew:

CUnknown * WINAPI CMyComponent::CreateInstance(LPUNKNOWN pUnk, HRESULT *pHr) 
{
    CMyComponent *pNewObject = 
        new CMyComponent(NAME("My Component"), pUnk, pHr );

    if (pNewObject == NULL)  
    {
        *phr = E_OUTOFMEMORY;
    }
    return pNewObject;
}

Requirements

Requirement Value
Header
Combase.h (include Streams.h)
Library
Strmbase.lib (retail builds);
Strmbasd.lib (debug builds)

See also

CFactoryTemplate Class