Setting Names in DLLs

You can use DLLs even though no macro sheet is present. However, you may want to define some names to help you keep data between calls to your DLL. For example, you may want to call xlfSetName from a DLL even though there is no macro sheet where you can define the name.

For this purpose, Microsoft Excel has a special, hidden name space that is accessible only to DLLs. This allows you to store temporary names in Microsoft Excel. However, it is important to remember that this name space is shared by all DLLs within the same instance of Microsoft Excel. Therefore, if you want to ensure that your names do not conflict with names defined by another DLL, be sure to begin all your names with a unique prefix, preferably the name of your DLL. For example, if your DLL is called MYDLL.DLL, create names such as MYDLL_hWnd.

The following is a way you might use the hidden name space:

The hidden name space is not accessible when the DLL is calculating a function on a worksheet. If the DLL function was called as part of a normal recalculation on a worksheet, names refer to the current sheet unless the DLL was registered as a macro type DLL (the data type string contained "#"). However, if the DLL was called from a macro sheet or if the DLL function was invoked through a menu, keyboard shortcut, toolbar, or otherwise, names will refer to the hidden name space.