调用dll绘制按钮的问题~~~~~~~~~~

colordancer 2008-09-08 04:12:19
主窗体A,引用的dll叫B
A的窗体中有一个按钮,点击后调用B中的函数f,f的功能是在A的界面上绘制一个新按钮

始终实现不了,要么出错,要么画不出来
我个人怀疑是
1·绘制的按钮是局部变量m,f执行完后,变量m即消失
2·我将m设成b的导出变量,但是执行时出错,将m设成static,或者设成指针,都出错

请帮忙
...全文
67 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
colordancer 2008-09-10
  • 打赏
  • 举报
回复
请问,为什么会出现以下错误?就是按照你的代码来写的:
colordancer 2008-09-09
  • 打赏
  • 举报
回复
非常感谢楼上的
我知道我的问题在哪了

结贴~~~
lizhigang34 2008-09-08
  • 打赏
  • 举报
回复
B中的函数是怎么创建按钮的??
下面是我写了一个,这是DLL工程

//////////////////////////////
//dll.h
CButton* CreateButton( LPCTSTR lpszCaption,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID );

//////////////////////////////
//dll.cpp
CButton* CreateButton(
LPCTSTR lpszCaption,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID)
{
CButton* pButton = new CButton;
BOOL bRet = pButton->Create(lpszCaption,
dwStyle,
rect,
pParentWnd,
nID
);
if (bRet == TRUE)
{
return pButton;
}
else
return NULL;
}

/////////////////////////////////
//dll.def
; Dll.def : Declares the module parameters for the DLL.

LIBRARY "Dll"
DESCRIPTION 'Dll Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
CreateButton


下面是测试DLL的工程

//Button的ID
#define IDC_BUTTON 1000

//导入函数
typedef CButton* (CREATE_BUTTON)(LPCTSTR lpszCaption,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID);
//单击确定按钮,创建一个Button
void CTestDlg::OnOK()
{
// TODO: Add extra validation here
//加载库
HMODULE hMoudle = ::LoadLibrary("Dll.dll");
if (hMoudle)
{
//得到导出函数
CREATE_BUTTON *pFunc = (CREATE_BUTTON* )::GetProcAddress(hMoudle, "CreateButton");
if (pFunc != NULL)
{
RECT rc = {20, 20, 100, 100};
CButton *pButton = pFunc("New Button", BS_PUSHBUTTON, rc, this, IDC_BUTTON);
//显示Button
pButton->ShowWindow(SW_SHOW);
}
}
// CDialog::OnOK();
}


colordancer 2008-09-08
  • 打赏
  • 举报
回复
晕倒
没人回答?

15,466

社区成员

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

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