我用Win32 Console Application生成工程
Insert -> New Class -> CMyClass(Generic Class) -> 完成类的编写(用_tmain调试通过)
如何再创建一个工程,把CMyClass做成DLL 详细说明

解决方案 »

  1.   

    做成DLL,看你是要求怎么用了?如果只是要导出DLL中的函数,那么可以用标准DLL,如果要导出类,那么只能用扩展DLL了最好的学习办法是拿一个DLL project 来看看,其实写DLL也很简单的。
    给我你的MAIL,我写个例子给你!
      

  2.   

    我的email:[email protected] 我要导出类的 3ku
    附件不要超过1mb
      

  3.   

    你这样定义类就行了:
    Class AFX_EXT_CLASS youClass
    {}
      

  4.   

    最好给个完整的源码 我想我碰到了很多细节问题
    要求 先写好类的文件 再生成ddl工程把类的文件include进去
      

  5.   

    比如你有一个类CExDlg(这里我用我的一个程序举例),写h文件:
    class AFX_EXT_CLASS CExDlg : public CDialog
    {
    // Construction
    public:
    CExDlg(CWnd* pParent = NULL);   // standard constructor// Dialog Data
    //{{AFX_DATA(CExDlg)
    enum { IDD = IDD_DIALOG_EX };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CExDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CExDlg)
    // NOTE: the ClassWizard will add member functions here
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };想加什么函数变量随你。cpp文件appwizard自动生成了,该怎么办就怎么办,跟别的mfc程序一样。建立一个mfc extend dll,名字叫cc(我起的)
    cc.cpp:static AFX_EXTENSION_MODULE CcDLL = { NULL, NULL };extern "C" int APIENTRY
    DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
    {
    // Remove this if you use lpReserved
    UNREFERENCED_PARAMETER(lpReserved); if (dwReason == DLL_PROCESS_ATTACH)
    {
    TRACE0("CC.DLL Initializing!\n");

    // Extension DLL one-time initialization
    if (!AfxInitExtensionModule(CcDLL, hInstance))
    return 0; // Insert this DLL into the resource chain
    // NOTE: If this Extension DLL is being implicitly linked to by
    //  an MFC Regular DLL (such as an ActiveX Control)
    //  instead of an MFC application, then you will want to
    //  remove this line from DllMain and put it in a separate
    //  function exported from this Extension DLL.  The Regular DLL
    //  that uses this Extension DLL should then explicitly call that
    //  function to initialize this Extension DLL.  Otherwise,
    //  the CDynLinkLibrary object will not be attached to the
    //  Regular DLL's resource chain, and serious problems will
    //  result. new CDynLinkLibrary(CcDLL);
    }
    else if (dwReason == DLL_PROCESS_DETACH)
    {
    TRACE0("CC.DLL Terminating!\n");
    // Terminate the library before destructors are called
    AfxTermExtensionModule(CcDLL);
    }
    return 1;   // ok
    }cc.def:
    ; cc.def : Declares the module parameters for the DLL.LIBRARY      "cc"
    DESCRIPTION  'cc Windows Dynamic Link Library'EXPORTS
        ; Explicit exports can go here so build,ok,get cc.dll。如何调用dll中的类呐?我做了一个例程invokedll,在你想使用CExDlg的类头文件中#include "ExDlg.h"(注意不必把这个文件加入工程),然后就可以象使用自己当前工程中的某个类一样使用它。
    invokedll.cpp:
    ........
    #include "ExDlg.h"
    ..........BOOL CinvokedllApp::InitInstance()
    {..........if (!ProcessShellCommand(cmdInfo))
    return FALSE; // The one and only window has been initialized, so show and update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow(); CExDlg  dlg;
    dlg.DoModal();..........
    }
    就这么简单,我都不大相信:)