AtlMarshalPtrInProc
创建新的流对象,编写代理的CLSID对流的,并通过编写必要的数据具有指定接口指针初始化代理到流中。
重要事项 |
---|
此功能无法在 Windows 运行时执行的应用程序。 |
HRESULT AtlMarshalPtrInProc(
IUnknown* pUnk,
const IID& iid,
IStream** ppStream
);
参数
拒绝
[out]一个指向要封送的接口的指针。iid
[in]封送的接口的GUID。ppStream
[out]一个指向 IStream 接口的指针在的位置使用的新流对象。
返回值
标准HRESULT值。
备注
MSHLFLAGS_TABLESTRONG 标志设置,使指针可以被封送到多个流。指针也可以unmarshaled多次。
如果已失败,释放流指针。
AtlMarshalPtrInProc 在处理对象的指针只能使用。
示例
//marshaling interface from one thread to another
//IStream ptr to hold serialized presentation of interface ptr
IStream* g_pStm;
//forward declaration
DWORD WINAPI ThreadProc(LPVOID lpParameter);
HRESULT WriteInterfacePtrToStream(IMyCircle *pCirc)
{
//marshal the interface ptr to another thread
//pCirc has to be pointer to actual object & not a proxy
HRESULT hr = AtlMarshalPtrInProc(pCirc, IID_IMyCircle, &g_pStm);
//m_dwThreadID is a DWORD holding thread ID of thread being created.
CreateThread(NULL, 0, ThreadProc, NULL, 0, &m_dwThreadID);
return hr;
}
DWORD WINAPI ThreadProc(LPVOID /*lpParameter*/)
{
// CoInitializeEx is per thread, so initialize COM on this thread
// (required by AtlUnmarshalPtr)
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (SUCCEEDED(hr))
{
IMyCircle* pCirc;
//unmarshal IMyCircle ptr from the stream
hr = AtlUnmarshalPtr(g_pStm, IID_IMyCircle, (IUnknown**)&pCirc);
// use IMyCircle ptr to call its methods
double center;
pCirc->get_XCenter(¢er);
//release the stream if no other thread requires it
//to unmarshal the IMyCircle interface pointer
hr = AtlFreeMarshalStream(g_pStm);
CoUninitialize();
}
return hr;
}
要求
Header: atlbase.h