Surendran T
Surendran T

Reputation: 67

DoModal Returns -1 Getlasterror says Invalid handle

I am using a Win32 application ,In this DoModal function returns -1 and GetlastError() returns 6(Invalid handle).I tried Deleting GDI handles to repair the GDI Exhausts,Result Fails.

Additional Information: I'm using Visual Studio 2012 and this application is for 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
}

Why I'm not getting the dialog box?

Upvotes: 2

Views: 746

Answers (1)

Santosh
Santosh

Reputation: 1815

DoModal() returns -1 when your resource is not mapped correctly with dialog. If you step into DoModal() you will find statement

// return -1 in case of failure to load the dialog template resource

I would suggest you to call AfxSetResourceHandle(); function before DoModal().

Upvotes: 1

Related Questions