다음을 통해 공유


AtlMarshalPtrInProc

프록시 CLSID를 스트림에 씁니다 새 스트림 개체를 만들고 프록시를 스트림으로 초기화 하는 데 필요한 데이터를 작성 하 여 지정 된 인터페이스 포인터를 마샬링합니다.

중요중요

이 함수를 실행 하는 응용 프로그램에서 사용할 수 있는 Windows 런타임.

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

요구 사항

헤더: atlbase.h

참고 항목

참조

AtlUnmarshalPtr

AtlFreeMarshalStream

MSHLFLAGS

기타 리소스

마샬링 전역 함수