共用方式為


封送處理全域函式

這些函式支援封送處理和將封送處理資料轉換成介面指標。

重要

下表所列的函式不能用於在 Windows 執行階段 中執行的應用程式。

名稱 描述
AtlFreeMarshalStream 釋放封送處理資料和 IStream 指標。
AtlMarshalPtrInProc 建立新的資料流程物件,並封送處理指定的介面指標。
AtlUnmarshalPtr 將資料流程的封送處理資料轉換成介面指標。

需求:

標頭: atlbase.h

AtlFreeMarshalStream

釋放資料流的封送處理資料,然後釋放資料流指標。

HRESULT AtlFreeMarshalStream(IStream* pStream);

參數

pStream
[in]資料流程上介面的 IStream 指標,用於封送處理。

範例

請參閱 AtlMarshalPtrInProc 範例。

AtlMarshalPtrInProc

建立新的資料流物件、將 Proxy 的 CLSID 寫入資料流,並且藉由將初始化 Proxy 所需的資料寫入資料流的方式封送處理指定的介面指標。

HRESULT AtlMarshalPtrInProc(
    IUnknown* pUnk,
    const IID& iid,
    IStream** ppStream);

參數

朋 克
[in]要封送處理之介面的指標。

Iid
[in]要封送處理之介面的 GUID。

ppStream
[out]用於封送處理之新資料流程物件上介面的指標 IStream

傳回值

標準 HRESULT 值。

備註

已設定MSHLFLAGS_TABLESTRONG旗標,以便將指標封送處理至多個資料流程。 指標也可以多次取消分界。

如果封送處理失敗,則會釋放資料流程指標。

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(&center);

      //release the stream if no other thread requires it 
      //to unmarshal the IMyCircle interface pointer
      hr = AtlFreeMarshalStream(g_pStm);

      CoUninitialize();
   }

   return hr;
}

AtlUnmarshalPtr

將資料流的封送處理資料轉換成可供用戶端使用的介面指標。

HRESULT AtlUnmarshalPtr(
    IStream* pStream,
    const IID& iid,
    IUnknown** ppUnk);

參數

pStream
[in]正在取消分流之資料流程的指標。

Iid
[in]未分批之介面的 GUID。

ppUnk
[out]未分封介面的指標。

傳回值

標準 HRESULT 值。

範例

請參閱 AtlMarshalPtrInProc 範例。

另請參閱

函數