Solved

DialogBoxParam returning error

Posted on 2002-04-24
10
1,067 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

747 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

10 Experts available now in Live!

Get 1:1 Help Now