Solved

DialogBoxParam returning error

Posted on 2002-04-24
10
1,090 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

856 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