Simple Chat Program
Environment: NT4 SP3; Developed with VC 60 SP3;
Unitalk2 is a simple talk with some strange detail:
- It's an application built on ATL technology
- It utilizes Connection Points
- The UniTalk application (UniTalk2.exe) acts as both the server and client depending on the start method*
*if you start the application from Explorer by double-clicking it, it acts as a client. The "other" instance to which it connects through DCOM is then the server.
UniTalk2 is a simple chat. Hence, you can talk via a network connection with another user. The application presents you with a standard (horizontal) split window format to distinguish the text you're writing from that of the remote computer.
In the combo box control, you can choose the friend to "call". The list displayed in the combo box is maintained via a simple text file named IpAddress.txt. When you choose to initiate a conversation with a remote machine, the user on that machine will see a dialog that informs him of an incoming chat request. They need only to simply click the Yes button to acknowledge the request and begin chatting when the application starts up.
Important Notes
- The UniTalk application (UniTalk2.exe) must be installed on both machines that want to participate in the chat.
- Both users must be on the same domain
- UniTalk2 is an interactive, COM-based application, that exchanges data across a network connection via DCOM. Therefore, you must configure dcomcnfg.exe for the launch of .exe
Description of the UniTalk2 Code
The _tWinMain function (UniTalk2.cpp) function decides (based on how the application was invoked) if it is to act as a server or client.
extern "C" int WINAPI _tWinMain(HINSTANCE hInstance,
HINSTANCE /*hPrevInstance*/, LPTSTR lpCmdLine, int nShowCmd)
{
if( nShowCmd == 1)
{
MainBool = true;
};
...
if( MainBool )
{
_ASSERTE(CCall2::mpDialo1 == NULL);
CCall2::mpDialo1 = new CDialogo(true);
CCall2::mpDialo1->DoModal();
}
else
{
// if MainBool is false, the appplication started in
// remote-mode and this branch of 'if' run
_ASSERTE(CCall2::mpDialo2 == NULL);
CCall2::mpDialo2 = new CDialogo(false);
CCall2::mpDialo2->DoModal();
//CCall2::mpDialo2->Create(NULL);
//CCall2::mpDialo2->ShowWindow(SW_SHOWNORMAL);
}
}
When CCall2::mpDialo1 is equal to "new CDialog(TRUE)", the application is launched as a chat client. Otherwise, it starts up as the server.
The central part of the application is the CDialog. This is responsible for the dialogs, creation of interfaces and creation of connection points. In the RunConnection() function, you can see the creation of the remote interface via the call to the standard COM function ::CoCreateInstanceEx() as well as the creation of CComObject<CRx2> (mpRx2 = new CComObject<CRx2>) that represents the connection-point.
void CDialogo::RunConnection()
{
USES_CONVERSION;
i = res = 0;
COSERVERINFO info;
MULTI_QI qi;
int result = 0;
info.dwReserved1 = NULL;
info.dwReserved2 = NULL;
info.pAuthInfo = NULL;
//info.pwszName = NULL;
info.pwszName = A2W(SelectedIp);
//info.pwszName = L"150.197.55.101";//max
qi.pIID = &IID_IUnknown;
qi.hr = 0;
qi.pItf = NULL;
int mConnCLCTX;
if (SelectedIp[0] == ''')
{
mLocalTalk = true;
info.pwszName = NULL;
mConnCLCTX = CLSCTX_LOCAL_SERVER;
}else
{
mConnCLCTX = CLSCTX_REMOTE_SERVER;
}
hr = CoCreateInstanceEx(CLSID_Call2,
NULL,
mConnCLCTX,
&info,
1,
&qi );
//ATLASSERT(hr==NOERROR);
if (!SUCCEEDED(hr))
{
::MessageBox(m_hWnd,
_T("Could not create ExeChat object."
" Make sure the server is registered."),
_T("Object Instantiation Error."),
MB_OK | MB_ICONINFORMATION);
// return 0L;
}
_ASSERT(qi.pItf != NULL);
hr = qi.pItf->QueryInterface(IID_ICall2,(void**)&pCall2);
_ASSERT(pCall2 != NULL);
hr = pCall2->QueryInterface(IID_IConnectionPointContainer,
(void **)&pConnPtContainer);
_ASSERT(SUCCEEDED(hr) && pConnPtContainer != NULL);
//BSTR per il chiamante
// wchar_t nome[] = L"ivan";
//BSTR mTempBstr = SysAllocString(nome);
hr = pCall2->Run(&res);
_ASSERT(SUCCEEDED(hr));
mpRx2 = new CComObject<CRx2>;
_ASSERT(mpRx2 != NULL);
((IRx2*)mpRx2)->AddRef();
hr = pConnPtContainer->FindConnectionPoint(IID_IRx2,
&m_pIRx2ConnectionPoint);
_ASSERT(SUCCEEDED(hr) && mpRx2 != NULL);
qi.pItf->Release();
pConnPtContainer->Release();
////////////////////////// Advise ////////////////////////
_ASSERT(mpRx2 != NULL);
hr = m_pIRx2ConnectionPoint->Advise((IUnknown*)mpRx2,
&m_dwCookie);
_ASSERT(SUCCEEDED(hr) && m_dwCookie != 0);
///////////////////////////////////////////////////////////
}
If the CDialogo::RunConnection() function returns without error, you are linked with your friend and are ready to chat.
Installation
- On each machine where you want to run UniTalk, you must register the UniTalk2 application by typing the following into the Windows "start box" (obviously, you'll need to qualify the name of the application with the name of the directory where the application resides):
<path>Unitalk2.exe -Regserver
regsvr32 <path>UniTalk2ps.dll;
- Default Properties tab
- Check the Enable Distributed COM on this computer check box
- In the Default Authentication Level combo box, select the None option
- In the Default Impersonation Level combo box, select the Delegate option
- Default Security tab
- On all Access, Launch and Configuration security, give "full control" to INTERACTIVE USER
- Application tab
- Double click UniTalk2 or IVirtInterface
- On the General tab, set the Authentication level to None
- On the Location tab, check the "Run application on this computer..." check box
- On the Security tab, set "full control" for the INTERACTIVE USER on Launch, Access and Configuration security
- On the Identity tab, check the "The Interactive user" check box
You must so configure Dcomcnfg.exe on the client and server machines.
Downloads
Download source code - 31 KbDownload UniTalk2 application - 41 Kb

Comments
maths calculator
Posted by ANSGAR on 12/04/2007 01:24amtextbox,1,2,3,4,5,6,7,8,9,0,+,-,*,/,=,%,clear
ReplyVEry good, but...
Posted by Legacy on 12/01/2003 12:00amOriginally posted by: Alfredo
I need a help , i construct a chat, but including sockets, & thread to send data,this data is separate to text (similar to msn, but point to point) you can help me????
thanks see yaa...
Replyreally it's perfect
Posted by Legacy on 10/30/2002 12:00amOriginally posted by: Mehul Choube
www.codeguru.com this site is really very useful for new cummer i really thanx to codeguru.com's team
ReplyGreat, guys! thanku...
Posted by Legacy on 03/18/2002 12:00amOriginally posted by: Sony
:-)
ReplyUniTalk2 Chat Program
Posted by Legacy on 02/27/2002 12:00amOriginally posted by: R.Saravanan MCA
very good
ReplyInstallation problem
Posted by Legacy on 02/06/2002 12:00amOriginally posted by: nix
Hi,
I am trying to configure the DCOM. but i enconutered a problem in getting to the Properties dialog.
I tried typing dcomcnfg in the RUN box but there is no such file or .exe.
Is the dcomcnfg.exe from the MSDN library or other programs?
Plus, I tried to compile the source code provided on the codeguru, there are some errors and I cannot build it.
I really need your help.
Waiting for your reply.
Regards.
Nix
Replycan it works on internet?
Posted by Legacy on 01/24/2002 12:00amOriginally posted by: klark_hu
i want to know that it can works on internet?
Replyif right,please tell me how to work?
thanks.
good
Posted by Legacy on 12/20/2001 12:00amOriginally posted by: sumitra
reality it is very good
Replythank you! but..
Posted by Legacy on 11/23/2001 12:00amOriginally posted by: zhtnuaa
Replythanx
Posted by Legacy on 11/19/2001 12:00amOriginally posted by: imran
that was really good
ReplyLoading, Please Wait ...