CoCreateInstance挂起在单线程exe COM客户端中
CoCreateInstance hangs in single-threaded exe COM client
我正在学习COM的基础知识。现在我正在编写进程外服务器。我写了相当基本的服务器应用程序,dll/stub和客户端应用程序。
若我注册服务器并在进程中使用CoCreateInstance创建对象的实例,它就可以工作:
服务器/客户端:
int _tmain(int argc, _TCHAR* argv[])
{
IClassFactory *factory = new ISimpleServerFactory();
DWORD classToken;
::CoInitialize(NULL);
CoRegisterClassObject(
IID_ISimpleServer,
factory,
CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE,
&classToken);
ISimpleServer *pISimpleServer = NULL;
HRESULT hr = CoCreateInstance(
CLSID_CSimpleServer,
NULL,
CLSCTX_LOCAL_SERVER,
IID_ISimpleServer,
(void **)&pISimpleServer); //<===========SUCCESS
if(SUCCEEDED(hr))
printf("Instantiation successfuln");
if(pISimpleServer != NULL)
pISimpleServer->Release();
std::cin.ignore();
CoRevokeClassObject(classToken);
::CoUninitialize();
return 0;
}
现在我尝试将其拆分为单独的应用程序:
服务器:
int _tmain(int argc, _TCHAR* argv[])
{
IClassFactory *factory = new ISimpleServerFactory();
DWORD classToken;
::CoInitialize(NULL);
CoRegisterClassObject(
IID_ISimpleServer,
factory,
CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE,
&classToken);
if(SUCCEEDED(hr))
printf("Instantiation successfuln");
if(pISimpleServer != NULL)
pISimpleServer->Release();
std::cin.ignore();
CoRevokeClassObject(classToken);
::CoUninitialize();
return 0;
}
客户:
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
SimpleServer::ISimpleServer *pISimpleServer = NULL;
HRESULT hr = CoCreateInstance(
CLSID_CSimpleServer,
NULL,
CLSCTX_LOCAL_SERVER,
IID_ISimpleServer,
(void **)&pISimpleServer); // HERE IT HANGS
if (SUCCEEDED(hr))
{
//*****SMTH***
}
else
{
printf("Failed to load COM object (server not loaded?)n");
}
if(pISimpleServer != NULL)
pISimpleServer->Release();
CoUninitialize();
std::cin.ignore();
return 0;
}
客户端挂起运行。如果服务器没有启动,客户端会键入"加载COM对象失败(服务器没有加载?)",所以我认为这不是服务器注册的问题。
但那会是什么呢?
好吧,就像Raymond指出的那样,我的服务器没有发送消息。我添加了
MSG msg;
while (GetMessage(&msg, 0, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(_kbhit())
break;
}
进入服务器主体,它变得更好:)
相关文章:
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 如何将函数集合传递给客户端类,以便将它们当作客户端类本身的成员使用
- 使用调试/崩溃报告将应用程序部署到客户端
- 如何在本地机器上运行c++和javascript客户端代码(hackerbank风格)
- 如何从客户端为COM服务器设置dll搜索路径?
- COM 客户端连接 COM 服务器所需的文件是什么(进程外方案)
- 与同时32和64位客户端同时使用Process COM服务器
- 从 MFC 客户端调用远程 COM 组件
- 多线程客户端中 COM 对象的初始化和实例化
- OOP COM 服务器更新客户端
- 将值 C#/COM 返回到客户端C++
- 一个C++客户端无法使用我们新的 COM 注册的 .NET .dll加载,另一个客户端可以正常工作
- COM 通过指针将C++结构从C++客户端传递到C++服务器
- 使用 VS2010 在客户端中编译本机 COM 客户端存根
- 在用C++编写的COM客户端中引发异常的Null返回值
- 验证进程外的COM服务器客户端是否受信任
- CoCreateInstance挂起在单线程exe COM客户端中
- COM无法正确地从托管服务器封送BSTR到本机客户端
- 如何在进程外客户端中获得免注册的COM对象代理
- 通过IDispatch公开COM函数的服务器如何区分调用函数而不传递任何ID参数的不同客户端?