omega_sword
asked on
User.exe errors
My program is intermittently causing illegal page faults in user.exe. Can anybody give me a hint on how to figure what in my program causes this? And possibly how to replicate the problem and solve it?
ASKER
My program gets distributed to different users, so I'm not so sure on which Windows version the error actually occurs.
These are the API calls that I use in Lib "user32" or Lib "user":
FlashWindow
GetCursorPos
GetDesktopWindow
GetSystemMetrics
GetWindowDC
GetWindowLongA
GetWindowRect
MoveWindow
ReleaseCapture
ReleaseDC
SendMessageA
SetWindowLongA
SetWindowPos
SetWindowTextA
I don't know what you mean by mixing up ByVals and ByRefs, though. I mean, you declare whether a parameter is a ByVal or a ByRef when you declare the API call, right? And when you actually use the API call, you merely pass the values, right? The declaration will determine what kind of parameter pass it is, right?
Regarding string length, I think the only API I use that has a string parameter is SetWindowTextA, and that parameter is declared simply as String, without any length specification. Is this a problem?
I don't understand what pasting code that runs often in my app will accomplish? I actually have something like that, a timer, but what should the code contain?
I only use hDC's from what you mentioned, I think. I'll check them out.
Thanks. Hope you can give me more info.
These are the API calls that I use in Lib "user32" or Lib "user":
FlashWindow
GetCursorPos
GetDesktopWindow
GetSystemMetrics
GetWindowDC
GetWindowLongA
GetWindowRect
MoveWindow
ReleaseCapture
ReleaseDC
SendMessageA
SetWindowLongA
SetWindowPos
SetWindowTextA
I don't know what you mean by mixing up ByVals and ByRefs, though. I mean, you declare whether a parameter is a ByVal or a ByRef when you declare the API call, right? And when you actually use the API call, you merely pass the values, right? The declaration will determine what kind of parameter pass it is, right?
Regarding string length, I think the only API I use that has a string parameter is SetWindowTextA, and that parameter is declared simply as String, without any length specification. Is this a problem?
I don't understand what pasting code that runs often in my app will accomplish? I actually have something like that, a timer, but what should the code contain?
I only use hDC's from what you mentioned, I think. I'll check them out.
Thanks. Hope you can give me more info.
User.Exe exceptions are almost always caused by a lack of free System Resources. This is a real problem on Win/9x machines since the system resource pools are LIMITED to only 64k (Win/NT does NOT have this problem).
The only thing you can do.. is load FEWER Graphical components / controls so that everything fits into the limited System resource space available. Please note.. that these are fewer components / controls for ALL RUNNING Applications.. (ie.. close ALL other unnecessary windows / programs.. of any running application to get more space).
In your own program.. I would seriously look at reducing the number of Graphical controls that you are using.
The only thing you can do.. is load FEWER Graphical components / controls so that everything fits into the limited System resource space available. Please note.. that these are fewer components / controls for ALL RUNNING Applications.. (ie.. close ALL other unnecessary windows / programs.. of any running application to get more space).
In your own program.. I would seriously look at reducing the number of Graphical controls that you are using.
I suggest keeping the number of controls down, period.
Control arrays use just as many resources (if not more) as normal controls, so I suggest exchanging comboboxes for sets of option buttons, etc. Also, graphical controls are definitely resource hogs. Same with UserControls, you wanna keep down the number of those onscreen at any time.
Control arrays use just as many resources (if not more) as normal controls, so I suggest exchanging comboboxes for sets of option buttons, etc. Also, graphical controls are definitely resource hogs. Same with UserControls, you wanna keep down the number of those onscreen at any time.
ASKER
That's gonna be a problem. Our GUI is filled with graphics. All the forms have background images, buttons are actually image controls, that even change image when you mouseover. But if graphics controls are the problem, how do graphics intensive apps, like Sonique, pull it off?
One trick is to use something like the Microsoft PictureClip Control (Project -> Components). In it.. you map in one huge picture.. and then you crop picture images out of it (rather then individually define them). Eg.
+---------------+--------- ------+
| | |
| | |
| | |
| | |
| A | B |
| | |
| | |
| | |
| | |
+---------------+--------- ------+
| | |
| | |
| | |
| | |
| | |
| C | D |
| | |
| | |
| | |
+---------------+--------- ------+
One big picture.. ie one set of Graphical resources.. that really contains 4 Graphic pictures A, B, C, D.
The only problem with the Microsoft Picture Clip control is that it can only handle bitmaps and it is somewhat limited in resolution.
Short of something like that.. you MUST make certain that whenever you are finished with a Graphic.. you MUST destroy it in order to recover its resources (keep your fingers crossed that the control you are destroying does NOT have a resource leak.. <groan>) AVOID Picture Boxes if you CAN (a real resource hog) and use Image Controls instead.
I want to remphasize.. that this is a Win9x problem.. the NT/2000 architecture allows for UNLIMITED resources. This System resource limitation has been in place ever since Win 3.11 (32k Resource limit for 3.11.. <sheesh>). Hopefully M$ will correct it in the future.
+---------------+---------
| | |
| | |
| | |
| | |
| A | B |
| | |
| | |
| | |
| | |
+---------------+---------
| | |
| | |
| | |
| | |
| | |
| C | D |
| | |
| | |
| | |
+---------------+---------
One big picture.. ie one set of Graphical resources.. that really contains 4 Graphic pictures A, B, C, D.
The only problem with the Microsoft Picture Clip control is that it can only handle bitmaps and it is somewhat limited in resolution.
Short of something like that.. you MUST make certain that whenever you are finished with a Graphic.. you MUST destroy it in order to recover its resources (keep your fingers crossed that the control you are destroying does NOT have a resource leak.. <groan>) AVOID Picture Boxes if you CAN (a real resource hog) and use Image Controls instead.
I want to remphasize.. that this is a Win9x problem.. the NT/2000 architecture allows for UNLIMITED resources. This System resource limitation has been in place ever since Win 3.11 (32k Resource limit for 3.11.. <sheesh>). Hopefully M$ will correct it in the future.
ASKER
Okay, got that. Basically just make sure to destroy graphics objects when done. But when you unload a form, will the resources used for the background image be recovered automatically? How about image controls on that form?
I remember using PaintPicture somewhere within the code and then have the form AutoRedraw = True...that eats up some resources as well, right? How do you recover resources used then?
Another kicker: I have a form that loads up several images. Now, I create several instances of that form depending on user input, so several can exist at any one time. Will resources used be multiplied by the number of instances even if I used the same graphics (from an imagelist control) over and over? Will using PaintPicture be better instead?
Thanks for the quick responses.
I remember using PaintPicture somewhere within the code and then have the form AutoRedraw = True...that eats up some resources as well, right? How do you recover resources used then?
Another kicker: I have a form that loads up several images. Now, I create several instances of that form depending on user input, so several can exist at any one time. Will resources used be multiplied by the number of instances even if I used the same graphics (from an imagelist control) over and over? Will using PaintPicture be better instead?
Thanks for the quick responses.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks wsh2.
Are you using any API calls that use Lib "User" or Lib "User32"? Also, are you running on Win9x, WinNT or Win2k? There's major differences between the three, but I'm guessing 9x because those errors don't happen much on NT/2k.
I suggest checking the variables you're passing to the API functions. You may be passing a Variable ByVal instead of ByRef, or vice-versa. Also, you could be sending a string, but specifying the wrong length.
I suggest pasting any code that runs often in your app. (Painting code, timer code, etc)
Also, make sure you're allocating and deallocating all your GDI stuff properly in your painting code, if you use any API to do painting you have to be careful. You ALWAYS need to deallocate:
hBrushes
hPens
hFonts
hDC's (ReleaseDC for DC's attached to hWnd's, DeleteDC otherwise)
If you add more info I can get more specific.