Click here to Skip to main content
15,909,656 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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
C++
[ 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 );
return S_OK;
}

In client
C++
if( FAILED( pDumpMessage ->DumpMessage((CComBSTR )m_csString)))


m_csString is Edit box variable

Please tell How to use console application in server
Posted
Updated 6-Jun-11 1:21am
v6
Comments
Richard MacCutchan 3-Jun-11 6:14am    
Have you included the correct header files? As you can see, the compiler cannot find a definition for CString.

use "class CString;" as a forward class declaration.
link error is because your ServerExe.exe is alreday running. stop that process.link error will be solved
 
Share this answer
 
Comments
Resmi Anna 3-Jun-11 6:26am    
I hope ur com server supports MFC
The clues are all there ...

you'll have to include the header for CString

#include <atlstr.h>


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 ...
 
Share this answer
 
v2
Comments
Sona from kerala 3-Jun-11 6:38am    
still
LINK : fatal error LNK1168: cannot open Debug/ServerExe.exe for writing
Error executing link.exe..
Resmi Anna 3-Jun-11 6:41am    
kill ur ServerExe.exe from task manager process
Sona from kerala 3-Jun-11 7:01am    
after adding that header file
fatal error C1083: Cannot open include file: 'atlstr.h': No such file or directory
Error executing cl.exe.
barneyman 3-Jun-11 7:13am    
oops - just noticed you're using VC6 ... CString is in MFC in that version; from memory adding MFC support was problematic (http://support.microsoft.com/kb/173974)

You may have more luck looking at this http://www.codeproject.com/KB/string/bstrsproject1.aspx

better u use LPCTSTR instead of CString. This seems to be better.
 
Share this answer
 
Comments
Sona from kerala 3-Jun-11 7:38am    
STDMETHODIMP CDumpMessage::DumpMessage( BSTR Message )
{
LPCTSTR msg(Message);
return S_OK;
}
1 error
error C2440: 'initializing' : cannot convert from 'unsigned short *' to 'const char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
you need to convert ur BSTR to LPCTSTR.
if your application doesnt support UNICODE do as below

[ id( 1 ), helpstring( "Chat" )] HRESULT DumpMessage([in]BSTR Message );
STDMETHODIMP CDumpMessage::DumpMessage( BSTR Message )
{
LPCTSTR lp = reinterpret_cast<lpctstr>(Message);
OutputDebugString(lp);
}</lpctstr>
 
Share this answer
 
Comments
Sona from kerala 3-Jun-11 7:54am    
thanks
Resmi Anna 3-Jun-11 8:06am    
pls mark it as solved if it is fine. why you have updated the qstn?
Sona from kerala 6-Jun-11 0:23am    
strings are not displyed in server.why?
Resmi Anna 6-Jun-11 1:04am    
you are saying that is not displayed in Debug Viewer??
Sona from kerala 6-Jun-11 1:06am    
ya

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900