紧急!!!vc制作的动态库为什么对话框不能被其他程序调用呢?下面是动态库代码,可以编译通过。但是在被调用时候出现下列提示错误:
debug assertion failed!
program:
       myvc.exe
file: 
       afxwin1.ini
       line 22下面是动态库代码,可以编译通过。
1。对话框类定义
class CCapture : public CDialog
{
// Construction
public:
CCapture(CWnd* pParent = NULL);   // standard constructor// Dialog Data
//{{AFX_DATA(CCapture)
enum { IDD = IDD_DIALOG1 };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCapture)
protected:
virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected: // Generated message map functions
//{{AFX_MSG(CCapture)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};2。在导出的函数中使用对话框类#include "stdafx.h"
#include "picforusb1.h"#ifdef _DEBUG 
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CPicforusb1App constructionCPicforusb1App::CPicforusb1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}/////////////////////////////////////////////////////////////////////////////
// The one and only CPicforusb1App objectCPicforusb1App theApp;
_declspec(dllexport) int CardCreate(void)
{ int nResponse = theApp.dlg.DoModal();//在导出的函数中使用对话框类
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
//  dismissed with Cancel
}}

解决方案 »

  1.   

    补充:CPicforusb1App类中定义了对话框实例:
    class CPicforusb1App : public CWinApp
    {
    public:
    CPicforusb1App();
    int m_nSlot;
    CCapture dlg;//CPicforusb1App类中定义了对话框实例:
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CPicforusb1App)
    //}}AFX_VIRTUAL //{{AFX_MSG(CPicforusb1App)
    // NOTE - the ClassWizard will add and remove member functions here.
    //    DO NOT EDIT what you see in these blocks of generated code !
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
      

  2.   

    参考MSDN,“Which Kind of DLL to Use”“If your DLL implements reusable classes derived from the existing MFC classes, or if you need to pass MFC-derived objects between the application and the DLL, then you must build an extension DLL.”你把动态库改成MFC扩展动态库试试。
      

  3.   

    这个问题在论坛上已经问过很多次了。建议先搜索一下。
    原因是在DLL中的Dialog在Load它的模班资源时,需要得到他自己的线程模块的句柄,从而获得资源;可以由于在DLL中使用资源时会先将当前的线程改为主程序的(afxapp),所以加载资源失败。论坛里提出了很多种解决方案,可以参考。我是通过重载dialog的创建过程实现的,不够灵活,可以参考一下其他人的意见。
      

  4.   

    首先你必须创建一个MFC 扩展DLL
    然后你应该在你的DLL中导出你的对话框类
    例如:
    class AFX_EXT_CLASS CCapture : public CDialog 
    {
    public:
    void CCapture ();
    CCapture ();
    virtual ~CCapture ();
    .......
    };可以参考一下下面的例子:
    http://www.vccode.com/file_show.php?id=1636