Simple Chat Program

. 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;	= 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


  • fake louis vuitton luggage bags dkwige

    Posted by Achiegaic on 05/16/2013 08:01pm 72670 828204louis vuitton 2012 collection fashion show lv belt on sale hermes香水 hermes Ë¿½í¹ÊÊÂ

  • maths calculator

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


  • VEry good, but...

    Posted by Legacy on 12/01/2003 12: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 12:00am

    Originally posted by: Mehul Choube this site is really very useful for new cummer i really thanx to's team

  • Great, guys! thanku...

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

    Originally posted by: Sony


  • UniTalk2 Chat Program

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

    Originally posted by: R.Saravanan MCA

    very good

  • Installation problem

    Posted by Legacy on 02/06/2002 12: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 12: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 12:00am

    Originally posted by: sumitra

    reality it is very good

  • thank you! but..

    Posted by Legacy on 11/23/2001 12: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?

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • U.S. companies are desperately trying to recruit and hire skilled software engineers and developers, but there's simply not enough quality talent to go around. In response, companies often resort to inferior solutions -- hiring substandard developers and engineers, recruiting talent on a part-time or temporary basis, poaching people from competitors, or burdening an already stressed IT staff for more of their labor. Fortunately, there's a better solution. Read this white paper to learn the business value of …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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