动态库调用对话框

typedef VOID (* lpFUN)(VOID);

class CDemoDlg : public CDialog
{//......

    lpFUN m_pfn;
    HINSTANCE m_hStkBrowse;

 

 

CdemoDlgKey* g_pdlg = NULL;
extern "C" __declspec (dllexport)  void DEMOFUN(void)
{
    g_pdlg = new CdemoDlgKey;
    if (g_pdlg->Create(IDD_DIALOGDemo))
    {
        g_pdlg->ShowWindow(SW_SHOW);
    }
}

 

void CdemoDlgKey::OnClose()
{
    CDialog::OnClose();
    delete this;
}

void CdemoDlgKey::OnDestroy()
{
    CDialog::OnDestroy();
    delete this;
}

 

 

 

CDemoDlg::CDemoDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CDemoDlg::IDD, pParent)
{
   //........
    m_hStkBrowse = NULL;
    m_pfn = NULL;
}

 

CDemoDlg::~CDemoDlg()
{
    if (m_hStkBrowse!=NULL)
    {
        FreeLibrary(m_hStkBrowse);
        m_pfn = NULL;
        m_hStkBrowse = NULL;
    }
}

 

void CDemoDlg::OnOK()
{
    if (m_hStkBrowse==NULL)
            m_hStkBrowse = ::LoadLibrary("DemoDLL.dll");

    if(m_hStkBrowse)
    {
        m_pfn = (lpFUN)::GetProcAddress(m_hStkBrowse,"DEMOFUN");
       
        if(m_pfn)
        {
            m_pfn();
            return;
        }
        FreeLibrary(m_hStkBrowse);
        m_pfn = NULL;
        m_hStkBrowse = NULL;
    }   
    CDialog::OnOK();
}

你可能感兴趣的:(动态库调用对话框)