小弟头一次写VC动态链接库,连具体步骤都不知道如何下手,网上的教程好多都是教如何调用函数,没有讲如何封装界面
各位大侠能帮一下忙,给点资料的链接吗祝大家身体健康

解决方案 »

  1.   

    你新建一个MFC extersion DLL(using shared mfc dll)就可以了。
      

  2.   

    然后你就在资源中插入一个对话框。再在Clase Wizard里为它添加一个类(也就是一个CDialog的派生类).  如: CMyDailog
    然后打开这个类的头文件.在class CMyDialog的中间加上AFX_EXT_CLASS,
    如class AFX_EXT_CLASS CMyDialog:public CDialog
    {
    ...
    }
    完成你需要的功能,编译.........在你的需要引用它的应用程序中#include这个头文件,设置好连接的lib.
    如:CMainFrame::OnTest()
    {
    CMyDialog dlg(this);
    dlg.domodal();
    }这就可以了.
      

  3.   

    http://blog.csdn.net/lixiaosan/archive/2006/04/29/697647.aspx
      

  4.   

    请参见我的帖子:
    http://community.csdn.net/Expert/topic/5023/5023170.xml?temp=.4453546
      

  5.   

    1.资源移到DLL中
    2.将代码移到DLL中
    3.如果是在动态库中使用MFC,在使用Dialog时记得
    AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
      

  6.   

    顶, 看到有文章说 “  MFC扩展DLL采用MFC的动态链接版本创建,它只能被用MFC类库所编写的应用程序所调用。... ...  "
    如果为PB等编写的应用程序调用,又如何处理呢?
      

  7.   

    AFX_MEANGE_STATE(AfxGetStaticModuleState());
      

  8.   

    // TestDll.cpp : Defines the initialization routines for the DLL.
    //#include "stdafx.h"
    #include "TestDll.h"
    #include "DlgDBConnect.h"
    #include "DlgRecordset.h"
    #include "DlgTableDesign.h"
    #include "DlgTest.h"
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    HWND hMainWnd;
    //
    // Note!
    //
    // If this DLL is dynamically linked against the MFC
    // DLLs, any functions exported from this DLL which
    // call into MFC must have the AFX_MANAGE_STATE macro
    // added at the very beginning of the function.
    //
    // For example:
    //
    // extern "C" BOOL PASCAL EXPORT ExportedFunction()
    // {
    // AFX_MANAGE_STATE(AfxGetStaticModuleState());
    // // normal function body here
    // }
    //
    // It is very important that this macro appear in each
    // function, prior to any calls into MFC.  This means that
    // it must appear as the first statement within the 
    // function, even before any object variable declarations
    // as their constructors may generate calls into the MFC
    // DLL.
    //
    // Please see MFC Technical Notes 33 and 58 for additional
    // details.
    ///////////////////////////////////////////////////////////////////////////////
    // CTestDllAppBEGIN_MESSAGE_MAP(CTestDllApp, CWinApp)
    //{{AFX_MSG_MAP(CTestDllApp)
    // NOTE - the ClassWizard will add and remove mapping macros here.
    //    DO NOT EDIT what you see in these blocks of generated code!
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CTestDllApp constructionCTestDllApp::CTestDllApp()
    {
    // TODO: add construction code here,
    // Place all significant initialization in InitInstance
    }/////////////////////////////////////////////////////////////////////////////
    // The one and only CTestDllApp objectCTestDllApp theApp;
    BOOL bIsOpenDB(FALSE);BOOL CTestDllApp::InitInstance() 
    {
    // TODO: Add your specialized code here and/or call the base class
    /* if (!AfxOleInit())
    {
    AfxMessageBox("ole ³õʼ»¯´íÎó");
    return FALSE;
    }*/ AfxEnableControlContainer();//
    return CWinApp::InitInstance();
    }extern "C" __declspec(dllexport) void showDBConndlg(HWND hWndParent)
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CDlgDBConnect dlg(CWnd::FromHandle(hWndParent));
    hMainWnd = hWndParent;
    dlg.DoModal();
    bIsOpenDB=TRUE;
    }
    extern "C" __declspec(dllexport) void showRecorddlg()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CDlgRecordset dlg(CWnd::FromHandle(hMainWnd));
    //hMainWnd=hWndParent;
    if(bIsOpenDB)
    dlg.DoModal();
    else
    ::MessageBox(NULL,"Êý¾Ý¿âδ´ò¿ª£¬ÇëÏÈÁ¬½ÓÊý¾Ý¿â£¡","Ìáʾ",MB_OK);
    }
    extern "C" __declspec(dllexport) void closeconn()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    // CDlgTest dlg(CWnd::FromHandle(hMainWnd));
    //dlg.DoModal();
    if(theApp.m_pConnection)
      {
      theApp.m_pConnection->Close();
      theApp.m_pConnection.Release();
    bIsOpenDB=FALSE;
      }}
    extern "C" __declspec(dllexport) void showTableDesigndlg()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    CDlgTableDesign dlg(CWnd::FromHandle(hMainWnd));
    //hMainWnd=hWndParent;
    if(bIsOpenDB)
    dlg.DoModal();
    else
    ::MessageBox(NULL,"Êý¾Ý¿âδ´ò¿ª£¬ÇëÏÈÁ¬½ÓÊý¾Ý¿â£¡","Ìáʾ",MB_OK);

    }extern "C" __declspec(dllexport) void showTestdlg()
    {
    AFX_MANAGE_STATE(AfxGetStaticModuleState()); CDlgTest dlg(AfxGetApp()->GetMainWnd());
    //hMainWnd=hWndParent;
    if(bIsOpenDB)
    dlg.DoModal();
    else
    ::MessageBox(NULL,"Êý¾Ý¿âδ´ò¿ª£¬ÇëÏÈÁ¬½ÓÊý¾Ý¿â£¡","Ìáʾ",MB_OK);}