Using Hooks in Independent Modules

I have a question about using a Menu Hook Function in an Independent Modules. The following options do not work for me:

#pragma IndependentModule=MyModule

SetIgorHook IgorMenuHook=TestTheMenu    // does not work with this line
SetIgorHook IgorMenuHook=MyModule#TestTheMenu    // does not work with this line
SetIgorHook IgorMenuHook=MyModule#MyModule#TestTheMenu    // does not work with this line

Static Function TestTheMenu(...)
   ...

end


Neither does the following direct setup:

#pragma IndependentModule=MyModule

Function IgorMenuHook(...)
   ...

end


Is this a limitation of Independent Modules, a my misunderstanding of the text on page IV-41 of the manual ...

Quote:

However, if need be, you can call static functions in the independent module from outside the group using a triple name syntax:

imName#modName#functionName()


... or a limitation of Independent Modules AND IgorMenuHook functions?

BTW, I am still generally confused about the first two names in the triple name sequence imName#modName#functionName. What is the modName of an Independent Module?
I could be wrong here, but I think your problem is that if you declare a function as static, you need to include a #pragma ModuleName = mn type directive in that procedure file. That's the middle name of the triple name syntax. If you have a function in an independent module but it's not a static function, you don't need the middle name.

I'm not sure if you can use functions in independent modules with SetIgorHook, but if you can, your first example would probably look like this:
#pragma IndependentModule=MyModule
#pragma ModuleName=foo
 
SetIgorHook IgorMenuHook=MyModule#foo#TestTheMenu    // does not work with this line
 
Static Function TestTheMenu(...)
   ...
 
end


With independent modules, I don't think that you need to use static functions in most cases, since the function name space of the independent module is separate from other functions that are in other independent modules or not in independent modules at all.
aclight wrote:
I could be wrong here, but I think your problem is that if you declare a function as static, you need to include a #pragma ModuleName = mn type directive in that procedure file. ...


After further tests I found, if you use a Static function, AND you want to access it from outside the procedure file, then you MUST use a ModuleName pragma. Try the following in the procedure window:

Function TestMe()

    print "Hello World!"
    testyou()
    return 0
end

Static Function TestYou()

    print "Hello Universe!"
    return 0
end


Executing testme() on the command line works to print "Hello World!" and "Hello Universe!", however testyou() is inaccessible at the command line level. Putting this code into a Procedure window with a ModuleName=Tester pragma makes Tester#TestYou() accessible and keeps the simple call TestMe() still accessible.



So, with regard to naming functions to avoid conflicts ...

1) In any type of procedure file, the names of Static functions are always local.
2) When a procedure file or files have a ModuleName pragma, the names of Non-Static functions are still global.
3) When a procedure file or files have an IndependentModule pragma, the names of all functions are local.

When a function name is global, you should use a unique name (ie, GXY_Create(...) rather than Create(...)) to avoid potential conflicts with a (global) function using the same name in a different procedure file. When a function name is local, you can use any name you want.



Also, with regard to interactions of ModuleName and IndependentModule pragmas with Static or Non-Static functions ...

1) When a procedure file or files have a ModuleName pragma, you access Static functions from outside the module using the ModuleName#FunctionName(...) syntax.
2) When a procedure file or files have an IndependentModule pragma, you access any function from outside the independent module using the IndependentModuleName#FunctionName(...) syntax.
3) When a procedure file or files have both a ModuleName and an IndependentModule pragma, you access Non-Static functions from outside the module using the IndependentModuleName#FunctionName(...) syntax.
4) When a procedure file or files have both a ModuleName and an IndependentModule pragma, you access Static functions from outside the module using the IndependentModuleName#ModuleName#FunctionName(...) syntax.

Remember, when you design controls on control panels, their procedure files run as though they were called from outside the procedure file. Therefore, you must use the corresponding IndependentModuleName#FunctionName, ModuleName#FunctionName, or IndependentModuleName#ModuleName#FunctionName syntax.



(Just thought I would be expansive for the sake of anyone reading this who is new to Igor programming)

aclight wrote:
I'm not sure if you can use functions in independent modules with SetIgorHook, ...


My tests show, you CANNOT use IgorMenuHook(...) from within an IndependentModule. Apparently, it is never called.

Perhaps, short of breaking the procedure file into two pieces (Regular with the IgorMenuHook(...) function and IndependentModule with everything else), someone has a suggestion on how to have an IgorMenuHook(...) function recognized when it is within a procedure that is an IndependentModule.

Alternatively, the inaccessibility of Igor hook functions might be a fifth Limitations of Independent Modules to add to page IV-41 of the manual.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
The ability to use SetIgorHook to call routines in an independent module will be part of Igor 6.1.

Jim Prouty
WaveMetrics, Inc.
Has this feature been implemented yet? I am using 6.22A but hooks are not working for me when they are placed in independent modules.
For an example, execute this:
DisplayHelpTopic "Independent Modules in Action Procedures and Hook Functions"

I'm trying to use a menuHook, and I wrote one that works but when I move it to an independent module it is no longer activated.
erin.chapple wrote:
I'm trying to use a menuHook, and I wrote one that works but when I move it to an independent module it is no longer activated.
Post the code, including #pragmas here (along with the version of Igor and the version of the operating system), and maybe we can figure it out from that.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Thanks for responding guys. It looks like I was setting up the hook wrong. I got it working by running this command from ProcGlobal:
setIgorHook igorMenuHook = #

Simply calling the hook function igorMenuHook and placing it in an independent module doesn't work, even though it does work from ProcGlobal.
This may shed a little more light on this question. My recent testing showed that using hook functions with a predefined name (AfterCompiledHook, for example) in an independent module will not be called by the event unless they are Static functions. For example the following hook will not fire:
#pragma rtGlobals=1     // Use modern global access method.
#pragma IndependentModule= MyModule

Function AfterCompiledHook()
print "here AfterCompiledHook"
return 0
End



While it will fire when preceded by "Static":
#pragma rtGlobals=1     // Use modern global access method.
#pragma IndependentModule= MyModule

Static Function AfterCompiledHook()
print "here AfterCompiledHook"
return 0
End

jtigor wrote:
This may shed a little more light on this question. My recent testing showed that using hook functions with a predefined name (AfterCompiledHook, for example) in an independent module will not be called by the event unless that are Static functions. ....


Hmmm .... ? I wonder how this fits in the context of this thread?

http://www.igorexchange.com/node/1688

Seems as though some concrete examples would be helpful.

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville