/********************************************************************************\
*  This sample is supplied as is with no implied warranty.  
*  It is designed to assist you in using the Cisco AnyConnect VPN API. 
*  It is assumed that you will build a production application and 
*  refer to this sample as a reference only.
\********************************************************************************/
#include "stdafx.h"
#include "CppComSample.h"
#include "CppComSampleDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

BEGIN_MESSAGE_MAP(CCppComSampleApp, CWinApp)
    ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()

//You need a global CComModule to use ATL COM coclass like CEventCallBack.
//NOTE: CComModule is used so that this example can be potentially backported to VC6.
//      You can convert this to ATL 7.x or later COM if you want to.
CComModule _Module;

CCppComSampleApp::CCppComSampleApp()
{
}


// The one and only CCppComSampleApp object
CCppComSampleApp theApp;


BOOL CCppComSampleApp::InitInstance()
{
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    InitCtrls.dwICC = ICC_WIN95_CLASSES | ICC_STANDARD_CLASSES;
    ::InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();

    //Initialization of COM.  In this sample, COM is intentionally initialized
    //in STA mode so that the developer does not have to worry about threading and
    //serialization.  See ReadMe_First.htm for more details on this topic.
    //
    HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED 
                                            | COINIT_DISABLE_OLE1DDE
                                            | COINIT_SPEED_OVER_MEMORY);
    if (FAILED(hr))
    {
        ::MessageBox(::GetDesktopWindow(), _T("Unable to initialize COM"), 
                     _T("ERROR"), MB_OK | MB_ICONERROR);
        return FALSE;
    }
    else
    {
        AfxEnableControlContainer();
        SetRegistryKey(_T("AnyConnect VPN API Sample COM Application"));

        CCppComSampleDlg dlg;
        m_pMainWnd = &dlg;

        INT_PTR nResponse = dlg.DoModal();
        if (nResponse == IDOK)
        {
        }
        else if (nResponse == IDCANCEL)
        {
        }

    } // This scopes all COM smart pointers to ensure they are released.

    //All smart pointers must be cleaned up before COM is uninitialized or a crash will occur.
    ::CoUninitialize();

    return FALSE;
}
