Solved

DialogBoxParam returning error

Posted on 2002-04-24
10
1,077 Views
Last Modified: 2012-06-27
I am getting an error 1400 which is an "Invalid window handle". I have checked and the handle is correct. I just do not know where else to look. It is being called in the MainWndProc. The code below is an outtake from my project. Any help would be greatly appreciated. Thanks in advance.

John Saxon

int WINAPI MainWndProc(HWND hWnd, unsigned message, WPARAM wParam, LPARAM lParam)
{
  DLGPROC lpProcAbout;                  // pointer to the "About" function
  DLGPROC lpDialProc;                           // Pointer to Dial Selections
  DLGPROC lpNavSetup;                       // Pointer to Navigator dialog
  DLGPROC lpCommDlg;                // pointer to the "Network hostname" dialog
  RECT rc;
  GLOBALHANDLE hgMem;
  LPSTR lpData;
  int i,j,sr,er,sc,ec, trow, tcol;    //VT
  DWORD dw ;
  CHAR szBuf[80];
  static HCURSOR hCursor;
  static BOOL bMouseMove;
  POINT ptTemp;

  BOOL bRet;                                            //VT

  switch (message)
  {  
           case EMU_LOGIN:             /* Display login dialog box */
                lpProcAbout = MakeProcInstance(LoginDlg, hInst);
                    //hWnd = 0x081604FA;
                    DialogBoxParam(hInst, MAKEINTRESOURCE(LOGINBOX), hWnd, (DLGPROC)lpProcAbout, (LPARAM)0L);
                    dw = GetLastError();
                    sprintf(szBuf, " failed: GetLastError returned %u\n",dw);
                    MessageBox(NULL, szBuf, "Error", MB_OK);
                    //ExitProcess(dw);
                    FreeProcInstance(lpProcAbout);  
                break;

  }
  return (DefWindowProc(hWnd,message,wParam,lParam));
}
0
Comment
Question by:jsaxon2
  • 4
  • 3
  • 3
10 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 6966771
>>I am getting an error 1400 which is an "Invalid window handle".

Why do you know the 'DialogBoxParam()' call failed? You are not checking the return value. 'GetLastError()' will return some arbitrary value if there was no error before. But, if you want to use it, make sure to call 'SetLastError()' first, e.g.


SetLastError ( 0);
DialogBoxParam(hInst, MAKEINTRESOURCE(LOGINBOX), hWnd, (DLGPROC)lpProcAbout, (LPARAM)0L);
dw = GetLastError();

0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6966785
I know it fails because the dialog never displays. I did try your suggestion and am still getting the same error.
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6966790
Also, I did check the return value prior to using GetLast Error and it also was 1400.
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 6966816
OK, let's see then:

Is 'LOGINBOX' a valid resource ID? Where do you get 'hInst' from? Does it work with


DialogBoxParam(hInst, MAKEINTRESOURCE(LOGINBOX), hWnd, (DLGPROC)LoginDlg, (LPARAM)0L);

(The MakeProcInstance function is obsolete)?

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6969554
DialogBox and DialogBoxParam fail whenever there is a child window that can't be created.  This most often occurs when an ActiveX control is involved, but it could be a rich edit control, etc..  

To test to see if this is the problem, create a new dialog that contains only an OK button and try to bring it up instead.  If that works, look at each of the controls in the dialog box that is failing.

-- Dan
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:jsaxon2
ID: 6972300
It turns out tht the program was using some Borland specific controls that were not valid. That is why the dialogs were not diaplaying.

This is a program was written some years ago by a person that is no longer with the company. Unfortunately there are not many comments in the code. Thanks for your time.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6972402
>>using some Borland specific controls that were not valid.
So the solutuoin was apparently unrelated to any child windows that could not be created...

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 6972665
Yes, indeed, technically speaking, Dan should have received the points, as he was closest to the solution...
0
 
LVL 3

Author Comment

by:jsaxon2
ID: 6972710
I appologize, but I corrected the problem before I saw Dans post. I am posting points for Dan. Thanks for your help.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6974317
Proof at last!  The crying baby DOES get the milk!  -- Dan
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now