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);
  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
  • 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.

Downloads

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


Comments

  • fake louis vuitton luggage bags dkwige

    Posted by Achiegaic on 05/16/2013 08:01pm

    http://louisvuittonbelt.citationguide.net 72670 828204louis vuitton 2012 collection fashion show lv belt on sale hermes香水 hermes Ë¿½í¹ÊÊÂ

    Reply
  • maths calculator

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

    textbox,1,2,3,4,5,6,7,8,9,0,+,-,*,/,=,%,clear

    Reply
  • 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...

    Reply
  • really it's perfect

    Posted by Legacy on 10/30/2002 12: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

    Reply
  • Great, guys! thanku...

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

    Originally posted by: Sony

    :-)

    Reply
  • UniTalk2 Chat Program

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

    Originally posted by: R.Saravanan MCA

    very good

    Reply
  • Installation problem

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

    Originally 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

    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?
    thanks.

    Reply
  • good

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

    Originally posted by: sumitra

    reality it is very good

    Reply
  • 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?

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds