I am trying to use IExec->SetFunction() but can't seem to get it to work.
- OldOpenWorkbenchObject=(ULONG)IExec->SetFunction(WorkbenchBase,(long)-0x60,(unsigned long (*)())WEOpenWorkbenchObject);
- WEOpenWorkbenchObject(STRPTR Name,Tag tag1,...)
- IDOS->Printf("WEOpenWorkbenchObject() %s\n",Name);
- if (!OldOpenWorkbenchObject)
- IExec->SetFunction(WorkbenchBase,(long)-0x60,(unsigned long (*)())OldOpenWorkbenchObject);
I want to catch when someone opens a Workbench window (double click on DH0: icon or a drawer) to open my own window. The offset is from the pragmas. The examples I found use both positive and negative values. Tried both.
Is "OpenWorkbenchObjectA" the correct function to be patching?
I tried to also patch DisplayBeep() from IntuitionBase to make sure it was the right function to patch. Can't get that to work either.
Any ideas? OS4 examples?
SetFunction() is only for patching the legacy 68k jumptable of a library (code passed in must be 68k code or a trap instruction that redirects to a PPC function). SetFunction() is only really useful if the library you want to patch is 68k-only or if for some reason you want your patch to only apply to 68k programs using the library.
To patch PPC interfaces you need to use SetMethod().
Also all standard PPC library functions have a "hidden" first parameter which is the interface pointer (don't forget to add this) and if the function is a varargs function you need to use VARARGS68K in the function definition.
For some examples on how to use SetMethod() you can look at the td64patch and sashimi source codes:
OpenWorkbenchObject() is not what you are looking for.
Take a look at the workbench.library autodoc.
Workbench opens its windows via Intuition OpenWindow() passing a NewWindow struct.
So if you want to intercept opening a WB window, you need to patch OpenWindow() and check for the flags (look at intuition.h, struct Window/struct NewWindow) and the caller.
But this is by no means recommended to do. It is a hack.
SetFunction() was originally designed to fix bugs, when the OS was still in ROM. And this is done by SetPatch().
SetFunction()/SetMethod() is not meant for (3rd party) developers.
I got it working with some functions for testing (DisplayBeep()).
OpenWindow, OpenWindowTagList, and OpenWindowTags do not catch opening of Workbench windows.
I don't think patching a system library is a good idea or even necessary. Check out the Intuition function "StartScreenNotifyTags()". If you set the screen to WorkBench with the SNA_Pubname tag and then set the notification type with the SNOTIFY_AFTER_OPENWINDOW, you should get notification when Workbench opens a window. I haven't used it myself but there is no reason it shouldn't work.
X1000 - OS 4.1FE