XLL ��쐬����Creating XLLs

適用されますExcel 2013 |。Office 2013 |Visual StudioApplies to: Excel 2013 | Office 2013 | Visual Studio

DLL は、自己完結型は、またはその他のライブラリにのみ依存しています、その機能とコマンドにアクセスするための Microsoft Excel を有効にする方法を知る必要があります。If your DLL is self-contained or relies only on other libraries, you must know how to enable Microsoft Excel to access its functions and commands. 詳細については、 Excel でのアクセスの Dllを参照してください。For more information, see Access DLLs in Excel.

�������ADLL �� Excel �̋@�\�ɃA�N�Z�X����K�v������ꍇ (���Ƃ��΁A�Z���̓�e��擾����Ƃ���A���[�N�V�[�g�֐���Ăяo���Ƃ��A�܂��� Excel ��Ɖ�ă��[�N�X�y�[�X����擾����Ƃ��Ȃ�) �́A�R�[�h���� Excel �ւ̃R�[���o�b�N���”\�łȂ���΂Ȃ�܂���BHowever, if your DLL needs to access Excel functionality (for example, to get the contents of a cell, to call a worksheet function, or to interrogate Excel to obtain workspace information), your code must be able to call back into Excel.

Excel C API �ɂ́ADll ���� Excel �ւ̃R�[���o�b�N��”\�ɂ��邢���‚��̋@�\������܂��B�����ɃA�N�Z�X����ɂ́ADLL �� Excel �� 32 �r�b�g�Ń��C�u���� (xlcall32.lib) �ɃR���p�C�����ɐÓI�Ƀ����N������K�v������܂��B���̐ÓI���C�u�����́AMicrosoft Excel 2013 XLL SDK �̈ꕔ�Ƃ��� Microsoft ����_�E�����[�h�”\�ł��BXLL SDK �ɂ́A���̃��C�u������ 32 �r�b�g�ł� 64 �r�b�g�ł̗������܂܂�Ă��܂��BThe Excel C API provides several functions that enable DLLs to call back into Excel. To access these, the DLL must be linked statically at compile time with the Excel 32-bit library, xlcall32.lib. The static library is downloadable from Microsoft as part of the Microsoft Excel 2013 XLL SDK, which includes both 32-bit and 64-bit versions of this library.

Dll ���� Excel �ւ̃R�[���o�b�N��”\�ɂ���Enabling DLLs to Call Back into Excel

DLL �� Excel �̋@�\�ɃA�N�Z�X���ă��[�N�X�y�[�X����擾����ѐݒ�ł���悤�ɂ��邽�߂ɂ́A�܂� Excel �̃R�[���o�b�N�֐� Excel4�A Excel4v�A Excel12�A����� Excel12v �̃A�h���X��擾����K�v������܂��B�Ō�� 2 �‚̊֐��� Excel 2007 �œ������ꂽ��̂ł���A�㑱�̃o�[�W�����Ŏg�p�”\�ł��B�����̂��ׂĂɃA�N�Z�X����ɂ́ADLL �v���W�F�N�g�� Excel 2013 XLL SDK �̈ȉ��Ɏ����t�@�C���ւ̎Q�Ƃ�܂߂�K�v������܂��B (�ǂ̃o�[�W������ Excel �ɂ�܂܂��) �ŏ��� 2 �‚̃R�[���o�b�N�݂̂ɃA�N�Z�X����ꍇ�́A�ŏ��� 2 �‚̃t�@�C���݂̂�v���W�F�N�g�Ɋ܂߂�K�v������܂��BFor a DLL to be able to access the functionality in Excel and get or set workspace information, it must first obtain the addresses of the Excel callback functions Excel4, Excel4v, Excel12, and Excel12v. The last two were introduced in Excel 2007 and are available in subsequent versions. To access all of these, the DLL project must include references to the following files from the Excel 2013 XLL SDK. If you want to access only the first two callbacks (in any version of Excel), your project needs to include only the first two files.


Xlcall.h �t�@�C���ɂ́A���̍��ڂ��܂܂�܂��BThe Xlcall.h file contains the following items:

  • ���ׂẴR�[���o�b�N�֐��̊֐��v���g�^�C�v�BFunction prototypes for all callback functions.

  • DLL/XLL と ExcelDLL 間でのデータ交換にコールバックが使用するデータ構造の定義、データ型定数の定義。Definitions of the data structures that the callbacks use to exchange data between the DLL/XLL and Excel, and data-type constant definitions.

  • ���[�N�V�[�g�֐��A�}�N�� �V�[�g�֐��A����уT�|�[�g����Ă��� Excel �R�}���h�ɑ������� C API �֐��ƃR�}���h�̒�`�BDefinitions of the C API function and command equivalents of the worksheet, macro sheet functions, and supported Excel commands.

  • �R�[���o�b�N�֐��̖߂�l�̒�`�BDefinitions of callback function return values.

���̃t�@�C���ł́AC API �ɃA�N�Z�X���邷�ׂẴt�@�C���A�܂��� C API ���g�p����f�[�^�^��������邷�ׂẴt�@�C���ɂ����āA���̃t�@�C���� #include �f�B���N�e�B�u�� (���ځA���邢�͕ʂ̃w�b�_�[ �t�@�C�����ĊԐړI��) �g�p����K�v������܂��BYou should use the #include directive for this file, directly or indirectly via another header file, in all files that access the C API or that handle data types that the C API uses.


Xlcall32.lib ���C�u�����́A�ŏ��� 2 �‚̃R�[���o�b�N Excel4 ����� Excel4v �̑��A XlCallVer �֐���G�N�X�|�[�g���܂��B�v���W�F�N�g�ɂ��̃��C�u�����ւ̎Q�Ƃ��Ȃ��ƁA�R�[�h��ł����̃R�[���o�b�N�̂����ꂩ��g�p���Ă���ꍇ�A�����J�[�� XLL ��쐬�ł��܂���B(�����̊֐��̃A�h���X�́A�ʏ�� Excel �̃C���X�g�[���̈�‚Ƃ��ăV�X�e���ɃR�s�[����铯���� Xlcall32.dll �ɓ��I�Ƀ����N���邱�ƂŎ擾�ł��܂��B)The Xlcall32.lib library exports the first two callbacks, Excel4 and Excel4v, and also the XlCallVer function. Without a reference to this library in your project, the linker cannot create the XLL if you have used any of these callbacks in your code. (You can obtain the addresses of these functions by linking dynamically to the equivalent Xlcall32.dll that is copied to your system as part of a normal Excel installation.)


Excel �R�[���o�b�N Excel12 ����� Excel12v �� Xlcall32.lib �ł̓G�N�X�|�[�g����܂���B����ɂ��AExcel 2007 �ȍ�ō쐬���� XLL �v���W�F�N�g��������O�̃o�[�W������ Excel �ł����ł���悤�ɂȂ��Ă��܂��BXlcall.cpp ���W���[���ɂ́A Excel12 �֐��� Excel12v �֐��̃R�[�h���܂܂�Ă��܂��B�����́AExcel 2007 �ȍ�ł� Excel �̃G���g�� �|�C���g��Ăяo���A������O�̃o�[�W������ Excel ����s���Ă���ꍇ�͈��S�ȃG���[�l��Ԃ��܂��BExcel 2007 �ȍ~�œ��삵�A��K�͂ȃO���b�h�ƒ��� Unicode ��������������V�����f�[�^�^��g�p�ł��� XLL ��쐬����ꍇ�́A�v���W�F�N�g�ɂ��̃��W���[����܂߂�K�v������܂��BThe Excel callbacks Excel12 and Excel12v are not exported in Xlcall32.lib. This ensures that XLL projects that you create starting in Excel 2007 will also work with earlier versions of Excel. The Xlcall.cpp module contains code for the Excel12 and Excel12v functions, which call into an Excel entry point starting in Excel 2007, or return a safe error value if you are running an earlier version of Excel. You should include this module in your project if you want to create an XLL that runs starting in Excel 2007 and that is able to use the new data types that handle larger grids and longer Unicode strings.


Excel 2010 SDK �ȍ~�ł́A���̃t�@�C���� 32 �r�b�g�� 64 �r�b�g�̗����� XLL �ɃR���p�C���ł��܂��BStarting with the Excel 2010 SDK, this file can be compiled for both 32-bit and 64-bit XLLs.

DLL �� XLL �ɂ���:�A�h�C�� �}�l�[�W���[ �C���^�[�t�F�C�X�֐�Turning DLLs into XLLs: Add-in Manager Interface Functions

XLL は、Excel または Excel のアドイン マネージャーによって呼び出されるいくつかの手順をエクスポートする DLL です。An XLL is a DLL that exports several procedures that are called by Excel or the Excel Add-in Manager. これらの手順はここで簡単に説明し、アドイン マネージャーおよび XLL インターフェイスの関数で詳しく説明します。These procedures are described briefly here and discussed in detail in Add-in Manager and XLL Interface Functions. XlAutoのプレフィックスを持つすべてのこれらの DLL のコールバックを起動します。All of these DLL callbacks start with the prefix xlAuto. これらのコマンドのxlAutoOpenでは、1 つだけです。Only one of these, the command xlAutoOpen, is required. アドインをアクティブ化し、XLL 関数を登録するのには通常使用してコマンドを excel やその他の初期化タスクを実行するときに呼び出されます。It is called when the add-in is activated, and it is typically used to register XLL functions and commands with Excel and to do other initialization tasks. 後のセクションでは、関数のシグネチャとのすべてのxlAuto関数の実装の例が用意されています。The function signatures and example implementations of all of the xlAuto functions are provided in later sections.

�����̃R�[���o�b�N�̒��ŕK�{�Ȃ̂� xlAutoOpen �����ł����A�A�h�C���̓���ɂ���ẮA���̃R�}���h��G�N�X�|�[�g����K�v������”\��������܂��BEven though xlAutoOpen is the only required one of these callbacks, your add-in may also need to export others depending on its behavior.

Excel 2007 �ł́A��K�͂ȃO���b�h�ւ̑Ή��ƒ��� Unicode ������̃T�|�[�g�̂��߂ɁA�V�����f�[�^�^ XLOPER12 ����������܂����B XLOPER12 �ɂ‚��ẮA���̃g�s�b�N�Ō�ɐ�����܂��B xlAuto �֐��͌Â��f�[�^�^�ł��� XLOPER ��󂯎������Ԃ����肷��̂ɑ΂��AExcel 2007 �œ������ꂽ���̊֐��̐V�����o�[�W������ XLOPER12 �f�[�^�^��g�p���܂��B XLOPER12 ������ ���[�N������邽�߂Ɏ������K�{�ł��邱�Ƃ����� xlAutoFree12 ��ʂɂ���΁A���ׂẴo�[�W���� 12 �� xlAuto �֐��͏ȗ����Ă���S��̖��͂���܂���B�ȗ�����ꍇ�AExcel 2007 �ȍ~�� Excel �� XLOPER �o�[�W������Ăяo���܂��BExcel 2007 introduced a new data type, XLOPER12, to accommodate larger grids and to support long Unicode strings. XLOPER12 is described later in this topic. Whereas xlAuto functions take or return the old data type XLOPER, new versions of these functions were introduced in Excel 2007 that use XLOPER12 data types. With the exception of xlAutoFree12, which you must sometimes implement to avoid XLOPER12 memory leaks, you can safely omit all the version 12 xlAuto functions, in which case, starting in Excel 2007, Excel calls the XLOPER versions.


XLL ���A�N�e�B�u�������ƁAExcel �� xlAutoOpen �֐���Ăяo���܂��BExcel �Z�b�V�������J�n����Ƃ��ɂ́A����I�������O��� Excel �Z�b�V�����ŃA�N�e�B�u�ł������A�h�C�����A�N�e�B�u������܂��B�A�h�C���́AExcel �Z�b�V�������ɓǂݍ��܂��ƁA�A�N�e�B�u�ɂȂ�܂��B�A�h�C���́AExcel �Z�b�V�������ɔ�A�N�e�B�u��������A�ăA�N�e�B�u�������肷�邱�Ƃ��ł��܂��B�ăA�N�e�B�u������ۂɂ͊֐����Ăяo����܂��BExcel calls the xlAutoOpen function whenever the XLL is activated. The add-in will be activated at the start of an Excel session if it was active in the last Excel session that ended normally. The add-in is activated if it is loaded during an Excel session. The add-in can be deactivated and reactivated during an Excel session, and the function is called on reactivation.

XLL �̊֐��ƃR�}���h�̓o�^�A�f�[�^�\���̏������A���[�U�[ �C���^�[�t�F�C�X�̃J�X�^�}�C�Y�Ȃǂ�s���ɂ́A xlAutoOpen ��g�p����K�v������܂��BYou should use xlAutoOpen to register XLL functions and commands, initialize data structures, customize the user interface, and so on.

�A�h�C���� xlAutoRegister �֐��� xlAutoRegister12 �֐����������уG�N�X�|�[�g����ꍇ�AExcel ����� xlAutoOpen �֐���Ăяo�����Ɋ֐���R�}���h��A�N�e�B�u�ɂ��ēo�^���悤�Ƃ��邱�Ƃ�����܂��B���̏ꍇ�́A�֐��܂��̓R�}���h���������@�\����悤�ɁA�A�h�C�����\���ɏ���������Ă��邱�Ƃ�m�F����K�v������܂��B�����Ȃ��Ă��Ȃ��ꍇ�A�֐���R�}���h�̓o�^��A�K�v�ȏ������̎��s�����s���܂��BIf your add-in implements and exports the xlAutoRegister function or the xlAutoRegister12 function, Excel might attempt to activate and register a function or command without first calling the xlAutoOpen function. In this case, you should ensure that your add-in is sufficiently initialized for your function or command to work properly. If it is not, you should either fail the attempt to register the function or command, or carry out the necessary initialization.


XLL ����A�N�e�B�u�������ƁAExcel �� xlAutoClose �֐���Ăяo���܂��BExcel �Z�b�V����������ɏI������ƁA�A�h�C���͔�A�N�e�B�u������܂��BExcel �Z�b�V�������Ƀ��[�U�[���A�h�C�����A�N�e�B�u������ƁA�֐����Ăяo����܂��BExcel calls the xlAutoClose function whenever the XLL is deactivated. The add-in will be deactivated when an Excel session ends normally. If the user deactivates the add-in during an Excel session, the function is called.

�֐��ƃR�}���h�̓o�^����A���\�[�X�̉���A�J�X�^�}�C�Y�̉���Ȃǂ�s���ɂ́A xlAutoClose ��g�p����K�v������܂��BYou should use xlAutoClose to unregister functions and commands, release resources, undo customizations, and so on.


�֐��ƃR�}���h�̓o�^����Ɋւ��ẮA���m�̖�肪����܂��B�ڂ����́A�uExcel �A�h�C�� (XLL) �J���ɂ�������m�̖���v��������������BThere is a known issue with the unregistration of functions and commands. For more information, see Known Issues in Excel XLL Development.


Excel は、ユーザーは、アドイン マネージャーを使用して Excel セッション中に、XLL を起動するたびに、 xlAutoAdd 関数を呼び出します。Excel calls the xlAutoAdd function whenever the user activates the XLL during an Excel session by using the Add-In Manager. Excel が起動し、インストール済みのアドインをロードするとき、この関数は呼び出されません。This function is not called when Excel starts and loads a preinstalled add-in.

���̊֐���g�p���āA�A�h�C�����A�N�e�B�u�ɂȂ��Ă��邱�Ƃ���[�U�[�ɒʒm����J�X�^�� �_�C�A���O �{�b�N�X�̕\���A���W�X�g���ɑ΂���ǂݏ����A�܂��̓��C�Z���X���̊m�F��s�����Ƃ��ł��܂��BYou can use this function to display a custom dialog box that tells the user that the add-in has been activated, to read from or write to the registry, or to check licensing information.


Excel は、ユーザーが非アクティブ化、XLL Excel セッション中にアドイン マネージャーを使用してたびに、 xlAutoRemove関数を呼び出します。Excel calls the xlAutoRemove function whenever the user deactivates the XLL during an Excel session by using the Add-In Manager. Excel のセッションを終了すると、正常または異常では、アドインがインストールされていると、この関数は呼び出されません。This function is not called when an Excel session closes, normally or abnormally, with the add-in installed.

���̊֐���g�p���āA�A�h�C������A�N�e�B�u�ɂȂ��Ă��邱�Ƃ���[�U�[�ɒʒm����J�X�^�� �_�C�A���O �{�b�N�X��\��������A���W�X�g���ւ̓ǂݏ�����s�����Ƃ��ł��܂��BYou can use this function to display a custom dialog box that tells the user that the add-in has been deactivated, or to read from or write to the registry.


�A�h�C�� �}�l�[�W���[�� Excel �Z�b�V�����ŏ��߂ČĂяo�����Ƃ��AExcel �� xlAddInManagerInfo �֐���Ăяo���܂��BExcel �� 1 �Ɠ�����������n���ꍇ�A���̊֐��͕����� (�ʏ�́A�A�h�C���̖��O) ��Ԃ��K�v������܂��B����ȊO�̏ꍇ�́A #VALUE! ��Ԃ��K�v������܂��BExcel calls the xlAddInManagerInfo function when the Add-in Manager is invoked for the first time in an Excel session. If Excel passes an argument equal to 1, this function should return a string (typically, the name of the add-in); otherwise, it should return #VALUE!.

Excel 2007 �ȍ~�ł́A xlAddInManagerInfo12 �֐��� XLL �ɂ���ăG�N�X�|�[�g����Ă���ꍇ�AExcel �͂��̊֐��� xlAddInManagerInfo �֐�����D�悵�ČĂяo���܂��B�o�[�W�����ɂ���� XLL �̓���ɈႢ�������邱�Ƃ����邽�߂ɁA xlAddInManagerInfo12 �֐��� xlAddInManagerInfo �֐��͓�����������K�v������܂��B xlAddInManagerInfo12 �֐��� XLOPER12 �f�[�^�^��Ԃ��K�v������A xlAddInManagerInfo �֐��� XLOPER �f�[�^�^��Ԃ��K�v������܂��BStarting in Excel 2007, Excel calls the xlAddInManagerInfo12 function in preference to the xlAddInManagerInfo function if it is exported by the XLL. The xlAddInManagerInfo12 function should work in the same way as the xlAddInManagerInfo function to avoid version-specific differences in the behavior of the XLL. The xlAddInManagerInfo12 function should return an XLOPER12 data type, whereas the xlAddInManagerInfo function should return an XLOPER data type.


XLM �֐� REGISTER �܂��͂���Ɠ����� C API �֐� xlfRegister ���Ăяo���ꂽ�Ƃ��A�o�^�Ώۂ̊֐��̖߂�l�ƈ����̌^���w�肳��Ă��Ȃ��ƁAExcel �� xlAutoRegister �֐���Ăяo���܂��B xlAutoRegister �֐��ɂ��AXLL �͂��̓���ɂ���G�N�X�|�[�g���ꂽ�֐��ƃR�}���h�̃��X�g��������Ă��̊֐�������ƂƂ�ɓo�^���A�w�肳�ꂽ�^��Ԃ����Ƃ��ł��܂��BExcel calls the xlAutoRegister function whenever a call has been made to the XLM function REGISTER, or the C API equivalent xlfRegister function, with the return and argument types missing for the function being registered. The xlAutoRegister function allows the XLL to search its internal lists of exported functions and commands to register the function with the argument and return the specified types.

Excel 2007 �ȍ~�ł́A xlAddInRegister12 �֐��� XLL �ɂ���ăG�N�X�|�[�g����Ă���ꍇ�AExcel �͂��̊֐��� xlAddInRegister �֐�����D�悵�ČĂяo���܂��BStarting in Excel 2007, Excel calls the xlAddInRegister12 function in preference to the xlAddInRegister function if it is exported by the XLL.


�����Ɩ߂�l�̌^�̎w�肪�Ȃ��܂܂� xlAddInRegister/ xlAddInRegister12 ���֐���o�^���悤�Ƃ���΁A�ċA�I�ȌĂяo���̃��[�v���������A�ŏI�I�ɂ̓R�[�� �X�^�b�N���I�[�o�[�t���[���� Excel ���I�����邩�A�������Ȃ��Ȃ�܂��BIf xlAddInRegister/ xlAddInRegister12 tries to register the function without supplying the argument and return types, a recursive calling loop occurs that eventually overflows the call stack and causes Excel to close or stop responding.


Excel は XLL ワークシート関数は、 XLOPERを取得した後だけにxlAutoFree と xlAutoFree12関数を呼び出す/ XLOPER12のデータ型、メモリを解放する必要がある、xll ファイルを Excel に指示するフラグを設定します。Excel calls the xlAutoFree/xlAutoFree12 function just after an XLL worksheet function returns an XLOPER/ XLOPER12 data type with a flag set that tells Excel there is memory that the XLL still needs to release. これにより、配列、文字列、およびメモリ リークが発生せず、ワークシートへの外部参照を動的に割り当てられている xll ファイルに戻ります。This enables the XLL to return dynamically allocated arrays, strings, and external references to the worksheet without memory leaks. Excel 2007 以降では、 XLOPER12のデータ型はサポートされています。Starting in Excel 2007, the XLOPER12 data type is supported. �ڍׂɂ‚��ẮA�uExcel �̃������Ǘ��v��Q�Ƃ��Ă��������BFor more information, see Memory Management in Excel.


Excel 2007 以降では、Excel が設定されている場合にマルチ スレッドのワークシートの再計算、 xlAutoFreeを使用して、/ に返される関数を呼び出すだけで使用されていたのと同じスレッドでxlAutoFree12関数が呼び出されます。Starting in Excel 2007, when Excel is configured to use multithreaded worksheet recalculation, the xlAutoFree/ xlAutoFree12 function is called on the same thread that was just used to call the function that returned it. XlAutoFreeを/ 、その後のワークシートのセルは、そのスレッドで評価する前に、xlAutoFree12が常に行われます。The call to xlAutoFree/ xlAutoFree12 is always made before any subsequent worksheet cells are evaluated on that thread. これには、XLL でスレッド セーフでないデザインが簡素化されます。This simplifies thread-safe design in your XLL. 詳細については、 Excel で再計算をマルチ スレッドを参照してください。For more information, see Multithreaded Recalculation in Excel.

64 �r�b�g XLL �̍쐬Creating 64-bit XLLs

Excel ����у��[�U�[��`�֐��́A32 �r�b�g �I�y���[�e�B���O �V�X�e������D�ꂽ�p�t�H�[�}���X����҂ł��� 64 �r�b�g �I�y���[�e�B���O �V�X�e���Ŏ��s�”\�ł��BExcel �́A�f�[�^�̌^�Ɋւ������܂� XLOPER12 �\���̒l��n���܂��B XLOPER12 �\���ƃl�C�e�B�u�^ ( int �܂��͂��傫���^�ɒl��ێ�����|�C���^�[�Ȃ�) �̊ԂŒl��ϊ�����ꍇ�͂����ӂ��������BExcel and user-defined functions can run on 64-bit operating systems to take advantage of performance benefits over 32-bit operating systems. Excel passes values in XLOPER12 structures that include information about the types for the data. Be careful when you convert between values in the XLOPER12 structure and native types like int or pointers to preserve the values in the larger type.

�֘A����See also

関数ウィザードまたは [置換] ダイアログ ボックスから XLL 関数の呼び出しCall XLL Functions from the Function Wizard or Replace Dialog Boxes

[�A�h�C�� �}�l�[�W���[�� XLL �C���^��t�F�C�X�֐�Add-in Manager and XLL Interface Functions

Excel XLL �̊J��Developing Excel XLLs