求救! 本机运行正常,在有的机器上报错:必须的资源无法得到 !!!!

nickzwd 2005-01-04 10:33:50
我写了一个小工具,在本机上无论静态还是动态都已经调试通过,但是拿到一个没有安装VC的机器上就报错,说必需的资源无法得到。不知道哪里的问题。请高手帮忙。

我的OnPaint是这样写的,请问有问题吗?

有人说dc需要释放,如何释放啊?



void CDataBackupDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);

}
else
{
CDialog::OnPaint();
}
}
...全文
144 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
huakai8866 2005-01-07
  • 打赏
  • 举报
回复
CDialog::DoModal
Call this member function to invoke the modal dialog box and return the dialog-box result when done.

virtual INT_PTR DoModal( );
Return Value
An int value that specifies the value of the nResult parameter that was passed to the CDialog::EndDialog member function, which is used to close the dialog box. The return value is –1 if the function could not create the dialog box, or IDABORT if some other error occurred, in which case the Output window will contain error information from GetLastError.

Remarks
This member function handles all interaction with the user while the dialog box is active. This is what makes the dialog box modal; that is, the user cannot interact with other windows until the dialog box is closed.

If the user clicks one of the pushbuttons in the dialog box, such as OK or Cancel, a message-handler member function, such as OnOK or OnCancel, is called to attempt to close the dialog box. The default OnOK member function will validate and update the dialog-box data and close the dialog box with result IDOK, and the default OnCancel member function will close the dialog box with result IDCANCEL without validating or updating the dialog-box data. You can override these message-handler functions to alter their behavior.

Note PreTranslateMessage is now called for modal dialog box message processing.
Example
void CTstApp::OnAppAbout()
{
// Construct the dialog box passing the
// ID of the dialog template resource
CDialog aboutDlg(IDD_ABOUTBOX);

// Create and show the dialog box
INT_PTR nRet = -1;
nRet = aboutDlg.DoModal();

// Handle the return value from DoModal
switch ( nRet )
{
case -1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDABORT:
// Do something
break;
case IDOK:
// Do something
break;
case IDCANCEL:
// Do something
break;
default:
// Do something
break;
};
}
看看MSDN的
nickzwd 2005-01-07
  • 打赏
  • 举报
回复

如果你显式地调用资源释放函数,你可以使用 ASSERT() 对资源释放函数的放回值进行判断,我们很容易意识到要释放资源,确往往忘了检查释放是否成功,当要释放的 GDI 资源被选入一个 DC 后,DeleteObject() 将失败。

_AFXWIN_INLINE CGdiObject::~CGdiObject()
{ DeleteObject(); }

CBrush* CDC::SelectObject(CBrush* pBrush)
{
ASSERT(m_hDC != NULL);
HGDIOBJ hOldObj = NULL;

if (m_hDC != m_hAttribDC)
hOldObj = ::SelectObject(m_hDC, pBrush->GetSafeHandle());
if (m_hAttribDC != NULL)
hOldObj = ::SelectObject(m_hAttribDC, pBrush->GetSafeHandle());
return (CBrush*)CGdiObject::FromHandle(hOldObj);
}

这个是MFC的源代码,供参考(可以看出GDI对象的析构函数会做释放的动作,而在CDC::SelectObject中我没有看到释放的动作)。
nickzwd 2005-01-05
  • 打赏
  • 举报
回复
再次感谢大家的关注。

to : rainfall19831109(恩恩)

任何版本都不行的。我都试过了/也用了动态或者静态链接重复试了很多次。

to: chenjunge(狄克)

另一个机器可以肯定没有病毒的。而且系统一样都是2000server。

to:sungengyu(快乐机器)

其他人的出错情况总是不适用我这里,我也好郁闷啊。呵呵~~~~
rainfall19831109 2005-01-05
  • 打赏
  • 举报
回复
建成Realease的版本试过了吗??
nickzwd 2005-01-05
  • 打赏
  • 举报
回复
查了很多资料。问题还是没有解决。偶笨~~
bluestone 2005-01-04
  • 打赏
  • 举报
回复
你用的是Debug版本的吧,Release版本的也有问题吗?

Debug版本的EXE在没有安装VC的机器上是运行不了的。

Build->Set active Configration-> Release version。
nickzwd 2005-01-04
  • 打赏
  • 举报
回复
to lifezhu(来福) :

不行的。

我想程序可能不是出在这里,用Boundcheck重新编译也没有报错。真是没有办法了。超郁闷。
lifezhu 2005-01-04
  • 打赏
  • 举报
回复
ReleaseDC(&dc);
nickzwd 2005-01-04
  • 打赏
  • 举报
回复
哥们儿不行啊。我不但考这几个文件,我把所有相关联的dll都考过去了还是不行。
stevenliao11 2005-01-04
  • 打赏
  • 举报
回复
需要包含VC的动态库,将MFC42D.DLL MSVCIRTD.DLL MSVCRTD.DLL等提示所需要的DLL文件拷贝到执行文件目录下,就可以了。
chenjunge 2005-01-04
  • 打赏
  • 举报
回复
2000下编的程序在98下使用或者是那个机子中毒了
sungengyu 2005-01-04
  • 打赏
  • 举报
回复
我不知道,但是你可以用论坛的搜索,查找“必须的资源无法得到”

你遇到的问题以前肯定有人也遇到过了。
nickzwd 2005-01-04
  • 打赏
  • 举报
回复
sungengyu(快乐机器)

那我应该看什么地方呢 ?或者有什么好的方法去查原因啊
sungengyu 2005-01-04
  • 打赏
  • 举报
回复
如果怀疑 OnPaint 里面有问题,可以把里面注释掉再看看。
sungengyu 2005-01-04
  • 打赏
  • 举报
回复
不是 OnPaint 的问题。

别的地方。
nickzwd 2005-01-04
  • 打赏
  • 举报
回复
谢谢各位高手的关注。

上面的代码应该是没有问题的,因为我做的其他工具运行的都是好好的,代码一样的。


to: bluestone(kulawa)

Thank you ,但是也不行的,不是Release版本的问题。以前的都是Debug的,在没有VC的机器上可以运行的,都没有问题。不过我还是Release了一下,仍然不行。

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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