问题描述
需要开发一个ATL COM .exe服务器,该服务器将客户端应用程序发送的消息转储到控制台.插入的ATL对象应该具有接受字符串参数的接口方法"DumpMessage".客户端应用程序可以是基于MFC对话框的应用程序,该应用程序接受字符串并在按下按钮时将消息发送到COM服务器.这是我的代码:
在服务器中
An ATL COM .exe server needs to be developed which dumps the messages send by a client application to the console. ATL object inserted should have an interface method "DumpMessage" accepting a string argument.The client application can be an MFC dialog based application which accepts a string and sends the message to COM server on pressing a button.
This my code:
In Server
[ id( 1 ), helpstring( "Chat" )] HRESULT DumpMessage([in]BSTR Message );
STDMETHODIMP CDumpMessage::DumpMessage( BSTR Message )
{
LPCTSTR lp = reinterpret_cast<LPCTSTR >(Message);
OutputDebugString(lp);
MessageBox(NULL,lp,NULL,NULL);
返回S_OK;
}
在客户
MessageBox( NULL, lp, NULL, NULL );
return S_OK;
}
In client
if( FAILED( pDumpMessage ->DumpMessage((CComBSTR )m_csString)))
m_csString
是编辑框变量
请告诉如何在server
m_csString
is Edit box variable
Please tell How to use console application in server
推荐答案
#include <atlstr.h>
上一次使用COM EXE服务器后,它们通常会运行10分钟左右,因此您必须使用任务管理器将其杀死
修复这些问题后,您还需要从DumpMessage
方法中添加return S_OK;
(是的,从技术上讲,这是我的错)
我认为您可能想先跑步再行...
COM EXE Servers will generally run for 10 mins or so after they are last used, so you''ll have to kill it with task manager
When you''ve fixed those, you''re also going to have to add a return S_OK;
from the DumpMessage
method (yes, i know, technically, that''s my fault)
I think you may be trying to run before you can walk here ...
这篇关于需要开发一个ATL COM .exe服务器,该服务器将客户端应用程序发送的消息转储到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!