SetIgorHook and IndependentModules question/problem

Hi!

I have a problem using SetIgorHook in independent modules. I created a procedure which is run after IGOR starts and initializes a SetIgorHook which is defined in an independent module (IM). After this the hook function works as expected. BUT if I now close the experiment file (after saving it of course) and re-open it the hook function does not work (it does not get called). I have found out that just after the hook function is set using SetIgorHook the global string S_info presents in the form "IM#hookFunction;" (which works), BUT after re-opening the saved file this is changed to "ProcGlobal#IM#hookFunction;" which does not work any more. Deleting this "full path" and resetting it using just "IM#hookFunction;" makes the hook function being properly called again.

Is this a feature, an IGOR bug, my programming BUG or something else? Can anyone help in debugging this problem?

Thanks!

Gregor
UPDATE: I have just found a workaround (which seems to work) to this issue by not using the SetIgorHook operation but calling the IGOR hooks directly instead (like BeforeExperimentSaveHook for example). I still believe that there is an issue with using SetIgorHook in an independent module though.

EDIT: these have to be declared static in the independent module else they do not work (at least BeforeExperimentSaveHook was not working without being declared static, while for example AfterWindowCreatedHook was working also being public in the independent module).

Cheers,

Gregor
I have always had to relearn how to work with Independent Modules when it comes to making them do tricks. Do a search on "independent module" here and you will see some of the history of the type of questions that are asked.

I _think_ this indicates that you are trying to have the IM come back execute a function outside of itself without using the Execute command. Alternatively, it indicates that your syntax call to the IM is wrong from your main (non-IM) procedure. Or perhaps you have found a bug.

Could you post a shorted version of the IM and the main procedure to be tested?

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
The whole package is too large to post it as an example, therefore I quickly wrote an example (see attached IGOR experiment) which recreates the described behavior.

There is also a Notebook with instructions how to check and recreate the, in my opinion, weird (wrong) behavior.

Please check the attached IGOR experiment and try if you also get this behavior.

Thanks!

Gregor
IMSetIgorHookExample.pxp (15.52 KB)
This is a bug in Igor that will be fixed for the next release.

However, the fix requires that compilation of the re-opened experiment succeed well enough to locate the independent module.

You might be better off using a static hook function in the independent module rather than SetIgorHook.

DisplayHelpTopic "Static Hook Functions"

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
EDIT: Posted before I read the notice from above
********
OK. Got it.

When you first run, the IM is in no space, not even ProcGlobal. Hence, your first StartHook() call leaves the IM in no space (The Twilight Zone). When you quite and restart, the experiment loads the IM in ProcGlobal space. The IM gets pulled out of The Twilight Zone in to a place to reside. You can see this if, after you open, you try a StartHook() followed by a ShowHookName(). You will get ...

TestIM#ExperimentSaveNotification;ProcGlobal#TestIM#ExperimentSaveNotification;

Now, when you save, the hook runs (again).

I think you have two possible ways out of this. Include a IgorStartorNew hook function that kills and then resets the Before...Save hook function. Alternatively, rename the hook Before...Save hook function call. I am working on the latter.

This may be a bug, or it may be a caveat of how the IM is located at first start. I am still not clear.


--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
Thanks Jim for the clarification of the issue. I am now indeed calling the static hook functions directly in my IMs and it is working as expected.

Cheers,
Gregor