Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Automation Server Questions

Automation Server Questions

Scheduled Pinned Locked Moved C / C++ / MFC
c++sysadmindata-structurestestingbusiness
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    garyflet
    wrote on last edited by
    #1

    I'm using VC++ 6 service pack 6 on Windows 2000. I'm working with an automation server MDI application with the following requirements. 1) Can be started by user with visible interface. 2) Only one instance at a time. 3) If controlled by client, runs in background (invisible) initially. 4) Client(s) has option to make application visible. 5) If visible and user attempts to close with client(s) connections, warning is given with choice to close or not. 6) Has menu item that allows user to disconnect from all clients. 7) If invisible, closes when last client disconnects. I have no problem with 1-4, the questions arise with 5-7. In order to implement these, the server needs to know if there are clients connected to it. My main automation class (CAutoApp) is instantiated every time a client contacts it. In the constructor I add to a static array of LPUNKOWNs (m_lpUnk[MAXNUMCONN]) using GetInterface(&IID_IUnknown):

    LPUNKNOWN CAutoApp::m_lpUnk[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
    CAutoApp::CAutoApp()
    {
    EnableAutomation();
    for (int i=0; i < MAXNUMCONN && NULL != m_lpUnk[i]; i++);
    if (i < MAXNUMCONN)
    m_lpUnk[i] = GetInterface(&IID_IUnknown);
    }

    Whenever a client closes, CMainFrame::OnClose is called in the server. So I have the following code to implement 5 and 7 in OnClose():

    //see if any clients are still connected
    int i=0;
    while(i < MAXNUMCONN && NULL != CAutoApp::m\_lpUnk\[i\])
    {
    	try
    	{
    		CAutoApp::m\_lpUnk\[i\]->AddRef();
    		CAutoApp::m\_lpUnk\[i++\]->Release();
    	}
    	catch(...)
    	{
    		//connection no longer exists, remove from array
    		for(int j=i; j<MAXNUMCONN-1 && NULL != CAutoApp::m\_lpUnk\[j\]; j++)
    			CAutoApp::m\_lpUnk\[j\] = CAutoApp::m\_lpUnk\[j+1\];
    	}
    }
    
    //if connected to at least one client
    if (NULL != CAutoApp::m\_lpUnk\[0\])
    {
    	if (IsWindowVisible())
    	{
    		if (IDNO == AfxMessageBox("One or more remote connections is still active. Exit anyway?", MB\_YESNO))
    			//user decides not to close application
    			return;
    	}
    	else
    		//a client disconnected but do not close because other client(s) remain
    		return;
    }
                .....
         	CMDIFrameWnd::OnClose();
    

    This works, although maybe it's a no-no to use a try-catch this way. If there's a better way to do it, I'd like to know. To implement (6), I have the following:

    void CMainFrame::OnCloseconnections()
    {
    if (IDNO == AfxMessageBox("This will close all connections. Are y

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups