AtlMarshalPtrInProc

Crea un nuevo objeto de secuencia, escribe el CLSID del proxy a la secuencia, y calcula el puntero de interfaz especificado escribiendo los datos necesarios para inicializar el proxy en la secuencia.

Nota importanteImportante

Esta función no se puede utilizar en las aplicaciones que se ejecutan en Windows en tiempo de ejecución.

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

Parámetros

  • punky
    [in] un puntero a la interfaz que se formará.

  • iid
    [in] GUID de la interfaz que se forma.

  • ppStream
    [out] un puntero a la interfaz de IStream en el nuevo objeto de secuencia utilizado para formar.

Valor devuelto

Un valor estándar de HRESULT.

Comentarios

Se establece la marca de MSHLFLAGS_TABLESTRONG por lo que el puntero se puede calcular en secuencias.El puntero se puede también unmarshaled varias veces.

Si forma un error, se libera el puntero de secuencia.

AtlMarshalPtrInProc sólo se puede utilizar en un puntero a un objeto en proceso.

Ejemplo

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

Requisitos

encabezado: atlbase.h

Vea también

Referencia

AtlUnmarshalPtr

AtlFreeMarshalStream

MSHLFLAGS

Otros recursos

Funciones globales del cálculo de referencias