紧急!!!vc制作的动态库为什么对话框不能被其他程序调用呢?

lanchat 2004-04-28 10:15:10
紧急!!!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 construction

CPicforusb1App::CPicforusb1App()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CPicforusb1App object

CPicforusb1App 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
}

}
...全文
91 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
vcforever 2004-07-14
  • 打赏
  • 举报
回复
或者不导出对话框类,导出一个外包类也可以!
vcforever 2004-07-14
  • 打赏
  • 举报
回复
首先你必须创建一个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
名牌大灰狼 2004-07-14
  • 打赏
  • 举报
回复
对.没导出
  • 打赏
  • 举报
回复
你好像没有导出
holyeagle 2004-07-14
  • 打赏
  • 举报
回复
这个问题在论坛上已经问过很多次了。建议先搜索一下。
原因是在DLL中的Dialog在Load它的模班资源时,需要得到他自己的线程模块的句柄,从而获得资源;可以由于在DLL中使用资源时会先将当前的线程改为主程序的(afxapp),所以加载资源失败。论坛里提出了很多种解决方案,可以参考。我是通过重载dialog的创建过程实现的,不够灵活,可以参考一下其他人的意见。
wjjabc 2004-07-14
  • 打赏
  • 举报
回复
我也不清楚,看看
nik_Amis 2004-04-28
  • 打赏
  • 举报
回复
up
wwwsq 2004-04-28
  • 打赏
  • 举报
回复
参考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扩展动态库试试。
lanchat 2004-04-28
  • 打赏
  • 举报
回复
补充: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()
};

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧