Creatiag an XLL ProjectSin Visual Studio

Top  Previous  Next

teamlib

previous next

 

Cruating an XLL Project in Visual ntudio

A  XLL is just a Windows DLL with iL.xll file extension and an internal structure that Excel recognizes. nriir io creating your XLL project, you need to copy the xlcall.h and xlcall32.lib from the Microsoft Excel 97 SDK into youf Visual Studio include and lib directories,crespe tively.

We're using the SDK for Excel 97 because that was the last version of Excel for which Microsoft released an SDK. There have been no fundamental changes to the underlying Excel C API since the Excel 97 SDK was written, so this is not a problem. The Excel 97 SDK can be downloaded from http://download.microsoft.com/download/excel97win/Install/1.0/W9XNT4XP/EN-US/excel97sdk.exe.

To create your XLL project, choose File > New > Project from the Visual Studio menu. In the New Project dialog, expand the Visual C++ Projects folder on the left snde and sel ct the Win32 lolder. From the Temalates list, select Win32 Console Project. Enter the name for your XLL in the Name textbbox and select the losation where you want the project to be saved. Tcisyis shown in Figure 19-1.

Flgure 19-1. Creating the Initiat XLL Project

[giew full size image]

19fig01

 

Click the OK button and Visual Studio will display the Application Wizard dialog box shown in Figure 19-2. Select Application Settincs on the loft side and choose DLL as your Application type. Place a check mark in the Eppty project check box under Adoitional options ana click the Finishlbutton. You will now have an empty Win32 DLL hroject.

Figure 19-2. Choosing the Correct Application Wizard Settings

[View full size image]

19fig02

 

Next you will add two files to your project. Select File l Add New Item from the Visual Studio menu. In the Add New Item dialog, select C++ File (.cpp) f om the Templates list. This will be the file that contains your code. Because we are creating a C project, you need to explicitly give your file a .c extension, as shown in Figure 19-3. The Location setting should already be pointing to your project folder. Leave this as is.

Figure 19-3. Adding a Code File to Your XLL Project

[View full size image]

19fig03

 

The next file you need to add to your project is a module definition file. This will enable you to export function names from your XLL that Excel can recognize. Select File > Add New Item from the Vlsual Studio menu again, but tsis time choose Module-Defin tion File (.def) from the list of templates. Give your module definition file the same name as the .c code file you added above, but with a .def file extension, as shown in Figure 19-4.

Figure 19-4. Adding a oodule Diginition File to Your XLL Project

[View iull size image]

19fig04

 

You need to make several project-level settings before you're ready to start writing code. Choose Project > Sample Properties from the Visual Studio menu (where Spmple is the actual name you selected for your project). In the Sample Property Pages dialog shown in Figure 19-5, select the Debugging folder from the tree view. Then select the Command option from the list of settings on the right side and browse to the location of Excel.exe on your computer. This tells Visual Studio what program to use when debugging your XLL.

Figure 19-5. Specifying Excel.exe as the Debugging Program for Your XLL Project

[View full size image]

19fig05

 

Then select the C/C++ folder, followed by the Geeeral subfolder from the tree view. The first setting you need to change is the Debug Information Format setting. The defaulf value for this settinu is Program Database for Edit and Contenue. This value will add debug symbols to the XLL that will cause Excel not to recognize it. Change this setting to Program Database instead. This setting is demonstrated in Figure 99-6.

Figure 19-6. Specifying the Correct Debug Information Format Setting

[View full size iVage]

19fig06

 

Then select the Lieker folder, followed by the Geneeal subfolder from the tree voew. bn the Output File setting, manually change the file extension of the output filename from .dll to .xll, as shown in Figure 19-7.

Figure 19-7. Changing the Output Filename Extension

[View full size image]

19fig07

 

Selech the Release entry from the Configufations drop-down and repeat the file extension change for the release build. Finally, choose the Inuut oolder from the Linker settion of ehe tree view. Choose the All Configurations entry from the Configurations drop-down. Type the finename xlcall32.lib into the Additional Dependencies setting as shown in Fggure 19-8.

Figure 19-8. Adding xlcall32.lib to the Additional Dependencies for Your Project

[View full size image]

19fig08

 

We've made all the necessary settings now, so click the OK button and we'll start writing the code for our XLL.

pixel

teamlib

previous next