Don't try this at home!
Adventures in WPS programming
Chris Wohlgemuth
About the presenter
- WPS programming since the 90ies
- Projects:
- WPS Wizard
- Audio/Data-CD-Creator
- CW-Multimedia classes
- BubblePad
- CandyFolder
- ...
- Can frequently be found on IRC (usually Cinc on #netlabs)
What's this about?
- Talking about things you may see when doing WPS programming.
- How to workaround problems
- How to avoid problems in the first place
- Not about learning WPS programming
Before you start
- Have an archive of your desktop
- This backup shouldn't be from the stoneage
- Make sure emergency system really boots
- Know the command line (makeini and friends)
- Use SET RUNWORKPLACE=x:/os2/cmd.exe
WPS programming cycle
- Create or change IDL file
- Run IDL compiler
- Add your code
- Compile and link
Class installation
- SysRegisterClass()
- Restart WPS
- After installation:
- Just replace the DLL with the new one
- Restart WPS
- Hope for the best...
Hour clock Theater
Ooops! Hour clock instead of WPS.
Inevitable question...
Moment of truth
Do you have a desktop archive?
How to recover
- Rename the class DLL from the command line
- After the WPS is up again:
- Remove files and folders from the desktop
- Watch out for multimedia files
- Reinstall the class DLL
- Restart WPS
- Still no luck?
How to recover 2
- Rename the class DLL from the command line
- After the WPS is up again:
- Remove the .ICONPOS EA from the desktop folder
- Don't touch .CLASSINFO!
- Reinstall the class DLL
- Restart WPS
- Still no luck?
How to recover 3
- Reboot the system
- Still no luck?
"I have vermin to kill."
- The Bride -
Calling in the bug squashing squad
How to debug
- SET NOSHELLEXCEPTIONHANDLER=1
- Be careful with dialog boxes during startup
- Generally save: log files, but...
- Too much logging may cause deadlock!
Calling in the bug squashing squad
Watch out for
- Class loading in wpInitData()/wpclsInitData(): very bad idea
- Starting of threads in wpInitData()/wpclsInitData(): dangerous
- Executing Rexx scripts in wpInitData()/wpclsInitData(): dangerous
- Displaying windows during wpInitData()/wpclsInitData(): dangerous
Programming techniques
Tips and tricks
Rules
"...some may be bent, some may be broken."
- Morpheus -
Rules and the WPS
- Don't try to be a 1337 h4x0r. You will fail.
- Installation problems on the customers system
- You will introduce subtle bugs not visible on your system
- IBM bugs will render your hack useless
- Don't reverse engineer instance variable layout
- Next class revision may have a different layout
- There's probably a reason the instance variable is hidden
Rule of thumb
If there is no SOM API for it or no method to use/override it's a bad idea.
(Look into the SOM headers for little gems ;-) )
Resources
- Don't create huge bitmaps in the WPS process
- Don't create too many bitmaps in the WPS process
- Free resources after use
- Make sure they're really freed...
Exception handlers
Catch exceptions!
See XWP for an implementation
...but XWP is GPL!
See CandyFolder for an implementation (BSD)
...or just get except3.zip from Hobbes.
Exception handlers
TRY_LOUD(MODIFY_POPUP) {
/* Some code */
}
CATCH(MODIFY_POPUP) {
SysWriteToTrapLog("\nTrap in %s, file %s...", ...);
} END_CATCH;
"I've seen things you people wouldn't believe..."
- Roy Batty -
Example - Lucide thumbnails
- GIF file written to extended attribute
- Should be easy to load
- ...first try failed!?
EA data not prepended with size info.
Example - Lucide thumbnails part 2
- GIF file successfully loaded into memory
- MMOS2 fails to decode the data
- What the...
User installed replacement IO procedure which can't deal with memory files (in contrast to the IBM one).
Example - CWMM hogs resources
- CWMM loads image files to show them as icons
- Bitmap data is freed in wpUnInitData()
- WPS uses memory like crazy
XWP kept every object ever touched locked thus wpUnInitData() was never called.
Example - Method not called
- WPObject introduces wpObjectReady()
- WPObject is the root class for WPFolder, WPDataFile, WPURL, ...
- CWObject replaces WPObject and overrides wpObjectReady()
- For some classes wpObjectReady() in CWObject is never called
WPFolder eats the wpObjectReady() method call. The parent is not called.
Example - Weird parameters in method call
- Drag and drop from Firefox creates a WPUrl object
- Root class is WPObject replaced by CWObject
- wpObjectReady() in CWObject is called with an unexpected value
Investigation shows that the freshly created object is discarded somewhere in between the method calls and replaced by a new object behind our back.
The end
#netlabs on irc.freenode.net