用CoMarshalInterThreadInterfaceInStream调度接口指针时,为何总是不成功,请各位高手指点迷金

yangfanfan 2002-02-15 02:49:58
用CoMarshalInterThreadInterfaceInStream调度接口指针时,为何总是不成功,请各位高手指点迷金.
...全文
429 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
fantong 2002-02-21
  • 打赏
  • 举报
回复
建议如果很少调用的函数可以使用这个方法,频繁调用的不要用,偶感觉有点慢
fantong 2002-02-21
  • 打赏
  • 举报
回复
to:yangfanfan
嗬嗬,&号纯属笔误
IStream 上次确实是我自己创建的,
偶,再看了看自己创建IStream是脱裤子放屁,这是[out]参数嘛
代码不要赵抄阿,我只是说了这个流程,这些代码多半编译都通不过,
但是这个方法确实是可以的,我用它在一个窗口线程中创建的com中向另外一个工作线程传递一个接口参数,唉,说不清楚,画画图
(windowA (MycomB(functionC(),thread D())))
我在functionC中创建了MycomE,再将MycomE打包传递到thread D 中使用
这个办法是可以的
后来我舍弃了这段代码改用别的方法,所以代码没了
fantong 2002-02-20
  • 打赏
  • 举报
回复
first look up CoMarshalInterThreadInterfaceInStream in msdn,it use CoGetInterfaceAndReleaseStream to unmarshal Interface in the stream.
then you now how to do.
1. create a IStream ,do not write something in it
eg.
::CoInitialize(NULL);
HRESULT hr;
CComPtr<IStream> pStream;
hr=pStream.CoCreateInstance(CLSID_Stream);
2.then marshal your own interface to the stream

hr=CoMarshalInterThreadInterfaceInStream(IID_YOUWANT_MARSHAL_INTERFACE,pYourObj,pStream);
if hr=0,then you can pass the pStream to the other thread
3.unmarshal you obj from the stream
eg.
UINT Myfunc(void p)
{
//if the p is the stream pointer
CComPtr<IID_YOUWANT_MARSHAL_INTERFACE> pYourObj;
hr=CoGetInterfaceAndReleaseStream((IStream*)p
,IID_YOUWANT_MARSHAL_INTERFACE,(void**)pYourObj);
//the you have the pointer to you obj in the other thread,do not care about the release of IStream p
}
I just use the two function pass interface pointer cross thread and not test cross process ,that's long long ago and the source code is lost.this code maybe contain error because i write it here not copy it to here.the stream implement you can find in many component.eg the ado .to use it just use
#import "C:\Program Files\Common Files\System\ado\msado15.dll" named_guids,rename("EOF","adoEOF")
using namespace ADODB;
yangfanfan 2002-02-20
  • 打赏
  • 举报
回复
fantong(饭桶)兄:
你的代码我试过了,还是不行,
另外
hr=CoMarshalInterThreadInterfaceInStream(IID_YOUWANT_MARSHAL_INTERFACE,pYourObj,pStream);
应该为
hr=CoMarshalInterThreadInterfaceInStream(IID_YOUWANT_MARSHAL_INTERFACE,pYourObj,&pStream);
我想问你一个问题,msdn里面说CoMarshalInterThreadInterfaceInStream
这个函数已经包括创建Stream实例的工作,但是在你的代码中还是自己创建了实例,
拜托请回忆一下你的源代码,帮帮忙啦
rover1 2002-02-20
  • 打赏
  • 举报
回复
fantong(饭桶)兄:
请问如何把接口指针作为方法的参数传递,要用CoMarshalInterThreadInterfaceInStream,CoGetInterfaceAndReleaseStream吗?
yangfanfan 2002-02-16
  • 打赏
  • 举报
回复
我需要在另一个单元(STA)线程里激发引出接口的某个方法,所以需要调度引出接口的指针CoMarshalInterThreadInterfaceInStream这个函数就专门干这活的,但是老是不成功!!!
Tasehouny 2002-02-16
  • 打赏
  • 举报
回复
说详细一点!
lattice 2002-02-15
  • 打赏
  • 举报
回复
你问的问题真有水准,谁要是解答出来了绝对是顶尖高手

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧