Simple Chat Program


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

. Max Vigilante. Bartolo Sorrentino.

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);
  // 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);


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()
 i = res = 0;
 int result = 0;
 info.dwReserved1 = NULL;
 info.dwReserved2 = NULL;
 info.pAuthInfo   = NULL;
 //info.pwszName	 = NULL;
 info.pwszName	 = A2W(SelectedIp);
 //info.pwszName	= L"";//max

 qi.pIID = &IID_IUnknown;
 qi.hr	= 0;
 qi.pItf = NULL;

 int	mConnCLCTX;

 if (SelectedIp[0] == ''')
  mLocalTalk = true;

  info.pwszName	 = NULL;

 hr = CoCreateInstanceEx(CLSID_Call2,
                         &qi );
 if (!SUCCEEDED(hr))
               _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);
 mpRx2 = new CComObject<CRx2>;
 _ASSERT(mpRx2 != NULL);

 hr = pConnPtContainer->FindConnectionPoint(IID_IRx2, 
 _ASSERT(SUCCEEDED(hr) && mpRx2 != NULL);

 //////////////////////////	Advise	////////////////////////
 _ASSERT(mpRx2 != NULL);
 hr = m_pIRx2ConnectionPoint->Advise((IUnknown*)mpRx2, 
 _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.


  • 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
  • You must register UniTalk2ps.dll (this is the proxy/stub) on the machines of each user as follows:
  • regsvr32 <path>UniTalk2ps.dll;
  • Place the IpAddress.txt user database in the same directory with Unitalk2.exe
  • You must edit the IpAddress.txt text file and add the names and IP addresses of those with which you wish to chat.
  • You must configure DCOM (using the DCOMCNFG.EXE application) as follows:
    • 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.


Download source code - 31 Kb
Download UniTalk2 application - 41 Kb


  • maths calculator

    Posted by ANSGAR on 12/04/2007 09:24am


  • VEry good, but...

    Posted by Legacy on 12/01/2003 08:00am

    Originally 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...

  • really it's perfect

    Posted by Legacy on 10/30/2002 08:00am

    Originally posted by: Mehul Choube

    www.codeguru.com this site is really very useful for new cummer i really thanx to codeguru.com's team

  • Great, guys! thanku...

    Posted by Legacy on 03/18/2002 08:00am

    Originally posted by: Sony


  • UniTalk2 Chat Program

    Posted by Legacy on 02/27/2002 08:00am

    Originally posted by: R.Saravanan MCA

    very good

  • Installation problem

    Posted by Legacy on 02/06/2002 08:00am

    Originally posted by: nix

    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.


  • can it works on internet?

    Posted by Legacy on 01/24/2002 08:00am

    Originally posted by: klark_hu

    i want to know that it can works on internet?
    if right,please tell me how to work?

  • good

    Posted by Legacy on 12/20/2001 08:00am

    Originally posted by: sumitra

    reality it is very good

  • thank you! but..

    Posted by Legacy on 11/23/2001 08:00am

    Originally posted by: zhtnuaa

    Thank you.
    but can you provide some programes about chat for one in the domain ,and the others out the domain?

  • thanx

    Posted by Legacy on 11/19/2001 08:00am

    Originally posted by: imran

    that was really good

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date