COM 使用 CoMarshalInterThreadInterfaceInStream 封送接口
COM using CoMarshalInterThreadInterfaceInStream to marshal interface
我有一个在C++中注册函数和接口的方法,我正在使用CoMarshalInterThreadInterfaceInStream
来封送指向另一个线程中方法的接口指针。
在RegisterFunction
:
HRESULT hr = CoMarshalInterThreadInterfaceInStream(IID_Function, function, &stream);
在GetFunction
中发布它:
HRESULT hr = CoGetInterfaceAndReleaseStream(stream, IID_Function, reinterpret_cast<void**>(&function));
由于我将多次调用GetFunction
并且CoGetInterfaceAndReleaseStream
只释放一次流,因此如何保存流以再次使用它?
我尝试使用IGlobalInterfaceTable
,但我无法让它工作。
我在RegisterFunction
年成功注册了Inteface:
DWORD dwCookie = 0;
int a = 0;
if (pGIT == NULL) {
HRESULT hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGlobalInterfaceTable,
(void **)&pGIT);
if (hr != S_OK) {
throw _com_error(hr);
}
}
if (dwCookie == 0) {
HRESULT hr = pGIT->RegisterInterfaceInGlobal(function, IID_Function, &dwCookie);
if (hr != S_OK) {
throw _com_error(hr);
}
}
但是当我试图在GetFunction
中检索它时:
IGlobalInterfaceTable* GIT = NULL;
if (GIT == NULL) {
hr = CoCreateInstance(CLSID_StdGlobalInterfaceTable,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGlobalInterfaceTable,
(void **)&GIT);
if (FAILED(hr)) {
exit(0);
}
}
hr = pGIT->GetInterfaceFromGlobal(dwCookie, IID_Function, (void**)&function);
if (FAILED(hr)) {
exit(0);
}
当我尝试注册接口InGlobal时,我收到一个HR错误invalidArg(即使它使用与CoMarshalInterThreadInterfaceInStream相同的参数,除了cookie(
正如SoronelHaetil所说,你不能用CoMarshalInterThreadInterfaceInStream
做到这一点。它只能(取消(封送接口一次。
看看改用IGlobalInterfaceTable
。可以在表中注册一次 COM 对象,然后根据需要多次从任何线程/单元中的表中检索该对象,直到从表中撤消该对象。
你不能用CoMarshalInterThreadInterfaceInStream来做到这一点,它是一种方便的接口指针方法,只需提取一次。
相反,请使用CoMarshalInterface/CoUnmarshalInterface,并使用使用ShCreateMemStream创建的流。
相关文章:
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- Visual C++GC接口如何启用它以及要包含哪个库
- Windows.h与GLFW.h的接口
- 当字段可以为null时,如何使用C++接口在Avro中写入数据
- 提供与TMP和SFINAE的通用接口
- 为重写std::exception的库生成swig接口时出错
- 内联如何影响模块接口中的成员函数
- COM 接口 c# 封送数组数组
- 如何在 SCIP C++ 接口中获取 MILP 约束矩阵中的系数值
- 重载 -> shared_ptr 个实例中的箭头运算符<interface>,接口中没有纯虚拟析构函数
- 如何绑定 C++ gRPC 客户端的网络接口
- 模板化接口 - 创建一个泛型模板类以返回任何容器
- 如何从实现接口的模板化类实例访问结构
- 带有进度表的 curl 多接口程序
- 设计帮助 - 为不同类型的消息处理通用接口的设计模式
- 我可以在具有一个标头和一个接口的 cpp 文件中有多个嵌入吗?
- 类接口,可以创建N个方法
- 类具有相同的接口,但参数的类型不同
- 如何与 Cheerp/js 中的 extern 变量接口?
- 如何使用现代 CMake 安装捆绑的接口依赖项?