Funzioni globali di marshalling
Queste funzioni forniscono supporto per il marshalling e la conversione dei dati di marshalling in puntatori di interfaccia.
Importante
Le funzioni elencate nella tabella seguente non possono essere usate nelle applicazioni eseguite in Windows Runtime.
Nome | Descrizione |
---|---|
AtlFreeMarshalStream | Rilascia i dati di marshalling e il IStream puntatore. |
AtlMarshalPtrInProc | Crea un nuovo oggetto flusso e effettua il marshalling del puntatore all'interfaccia specificato. |
AtlUnmarshalPtr | Converte i dati di marshalling di un flusso in un puntatore di interfaccia. |
Requisiti:
Intestazione: atlbase.h
AtlFreeMarshalStream
Rilascia i dati del marshalling nel flusso, quindi rilascia il puntatore di flusso.
HRESULT AtlFreeMarshalStream(IStream* pStream);
Parametri
pStream
[in] Puntatore all'interfaccia IStream
nel flusso usato per il marshalling.
Esempio
Vedere l'esempio per AtlMarshalPtrInProc.
AtlMarshalPtrInProc
Crea un nuovo oggetto flusso, scrivere il CLSID del proxy nel flusso ed esegue il marshalling del puntatore a interfaccia specificato scrivendo i dati necessari a inizializzare il proxy nel flusso.
HRESULT AtlMarshalPtrInProc(
IUnknown* pUnk,
const IID& iid,
IStream** ppStream);
Parametri
Punk
[in] Puntatore all'interfaccia di cui effettuare il marshalling.
iid
[in] GUID dell'interfaccia sottoposta a marshalling.
ppStream
[out] Puntatore all'interfaccia sul nuovo oggetto flusso utilizzato per il IStream
marshalling.
Valore restituito
Valore HRESULT standard.
Osservazioni:
Il flag MSHLFLAGS_TABLESTRONG è impostato in modo che il puntatore possa essere sottoposto a marshalling su più flussi. Il puntatore può anche essere scollegato più volte.
Se il marshalling non riesce, viene rilasciato il puntatore di flusso.
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(¢er);
//release the stream if no other thread requires it
//to unmarshal the IMyCircle interface pointer
hr = AtlFreeMarshalStream(g_pStm);
CoUninitialize();
}
return hr;
}
AtlUnmarshalPtr
Converte i dati del marshalling del flusso in un puntatore a interfaccia che può essere utilizzato dal client.
HRESULT AtlUnmarshalPtr(
IStream* pStream,
const IID& iid,
IUnknown** ppUnk);
Parametri
pStream
[in] Puntatore al flusso di cui non è stato eseguito ilmarshaling.
iid
[in] GUID dell'interfaccia non sincronizzata.
ppUnk
[out] Puntatore all'interfaccia non conseguata.
Valore restituito
Valore HRESULT standard.
Esempio
Vedere l'esempio per AtlMarshalPtrInProc.