// AsynCallDemo.h : CAsynCallDemo 的声明

#pragma once
#include "resource.h"       // 主符号

#include "asyncall.h"
#include "AsynCallDlg.h"

#include <atlctl.h>

// CAsynCallDemo

class ATL_NO_VTABLE CAsynCallDemo : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CAsynCallDemo, &CLSID_AsynCallDemo>,
	public IDispatchImpl<IAsynCallDemo, &IID_IAsynCallDemo, &LIBID_asyncallLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
    public IObjectSafetyImpl<CAsynCallDemo, INTERFACESAFE_FOR_UNTRUSTED_CALLER| INTERFACESAFE_FOR_UNTRUSTED_DATA>
{
public:
    IDispatch *m_cbmethod;  /* 存放 js 函数对象，其实不必保存 */
    IStream *m_pStream ;
    CAsynCallDlg m_dlg;

    CAsynCallDemo()
        :m_pStream(NULL),m_cbmethod(NULL)
	{
	}

DECLARE_REGISTRY_RESOURCEID(IDR_ASYNCALLDEMO)


BEGIN_COM_MAP(CAsynCallDemo)
	COM_INTERFACE_ENTRY(IAsynCallDemo)
    COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IObjectSafety)
END_COM_MAP()


	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
        MSG msg;
        PeekMessageA(&msg,NULL,0,0,PM_NOREMOVE);
        m_dlg._ctl = this;
		return S_OK;
	}
	
	void FinalRelease() 
	{
        m_cbmethod->Release();
        m_pStream->Release();
        m_dlg.EndDialog(0);
	}

    void do_call(void);

public:
    STDMETHOD(SetDemoFunc)(IDispatch* jsFunc);
};

OBJECT_ENTRY_AUTO(__uuidof(AsynCallDemo), CAsynCallDemo)
