AtlMarshalPtrInProc

Crea un nuovo oggetto flusso, scrive il CLSID del proxy al flusso ed effettua il marshalling di un puntatore a interfaccia specificata la scrittura dei dati necessari per inizializzare il proxy nel flusso.

Nota importanteImportante

Questa funzione non può essere utilizzata nelle applicazioni eseguite in Windows Runtime.

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

Parametri

  • punk
    [in] puntatore All'interfaccia dal marshalling.

  • iid
    [in] Il GUID dell'interfaccia che viene eseguito il marshalling.

  • ppStream
    [out] puntatore All'interfaccia IStream nel nuovo flusso oggetto utilizzato per il marshalling.

Valore restituito

Un valore HRESULT standard.

Note

Il flag MSHLFLAGS_TABLESTRONG è impostato in modo da puntatore può essere eseguito il marshalling a più flussi.Il puntatore può essere unmarshaled più volte.

Se si desidera effettuare il marshalling di esito negativo, il puntatore di flusso viene rilasciato.

AtlMarshalPtrInProc può essere utilizzato solo su un puntatore a un oggetto in-process.

Esempio

//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;
}

Requisiti

Header: atlbase.h

Vedere anche

Riferimenti

AtlUnmarshalPtr

AtlFreeMarshalStream

MSHLFLAGS

Altre risorse

Il marshalling delle funzioni globali