【问题标题】:DoModal Returns -1 Getlasterror says Invalid handleDoModal 返回 -1 Getlasterror 说句柄无效
【发布时间】:2015-05-18 04:38:17
【问题描述】:

我正在使用 Win32 应用程序,在此 DoModal 函数中返回 -1 并且 GetlastError() 返回 6(无效句柄)。我尝试删除 GDI 句柄以修复 GDI 排气,结果失败。

附加信息: 我正在使用 Visual Studio 2012,此应用程序适用于 Compact 2013。

if(!bDeviceOpened)
{     
  bDeviceOpened=OpenDriver();


  if(bDeviceOpened == 0)
  {
    AfxMessageBox(_T("Please make sure the driver is up and runnning"));
    return FALSE;
  }

}

//Reading the Driver version
DWORD   nBytesReturned = 0;
    if(!GetOID(OID_RPS_DRIVER_STATS, &stats, sizeof(stats), &nBytesReturned) )
      {
        AfxMessageBox(_T("Failed to query the stats"));
      }

m_pMainWnd = &dlg;
int nResponse = 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
}

为什么我没有收到对话框?

【问题讨论】:

  • 你能调用“CommDlgExtendedError()”吗?
  • 现在 CommDlgExtendedError() 和 GetLastError() 返回 0,仍然 DoModal 为 -1
  • 不要使用 GetLastError(),当 DoModal() 返回 -1 时,它不会告诉你任何可靠的信息。该返回码只是意味着无法创建对话框,请使用调试器找出原因。单步执行代码。

标签: c++ visual-studio-2012 mfc dialog windows-ce


【解决方案1】:

DoModal() 当你的资源没有正确映射到对话框时返回 -1。如果你进入 DoModal() 你会发现语句

//如果加载对话框模板资源失败返回-1

我建议你在 DoModal() 之前调用 AfxSetResourceHandle(); 函数。

【讨论】:

  • @SurendranT 尝试评论/读取驱动程序版本 DWORD nBytesReturned = 0; if(!GetOID(OID_RPS_DRIVER_STATS, &stats, sizeof(stats), &nBytesReturned) ) { AfxMessageBox(_T("查询统计信息失败")); }"
猜你喜欢
  • 2013-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-10
  • 1970-01-01
  • 2023-04-03
  • 2014-08-02
  • 1970-01-01
相关资源
最近更新 更多