Welcome to MSDN Blogs Sign in | Join | Help

Quick detour #3: Updates we have made to XLLs

In the past few months, I have written a couple of articles (big grid, multi-threaded calculation) that prompted comments and questions along the lines of “what about XLLs?”  Since the email questions have actually been picking up in frequency (I guess a lot of readers are also XLL authors), I thought I would write a quick article that outlines the changes we are making in this area to support new functionality.

Stepping back for a minute, let me briefly explain XLLs.  An XLL is a DLL that is written so that Excel can open it directly.  XLLs can be used for a number of things, but (in my experience at least) the most common use of XLLs is creating user-defined worksheet functions (UDFs) to supplement Excel’s intrinsic functions.  Developers who write XLLs do so for a number of reasons, the paramount being performance.

We have made three changes to XLLs in Excel 12, primarily to give developers access to new functionality.  With Excel 12, XLL authors will have support for

  • The bigger grid
  • More function arguments
  • Multi-threaded calculation

Big grid and more arguments
When building an XLL today, developers can use a special Excel data type called an “XLOPER”.  An XLOPER is essentially a structure that allows developers to pass data types like references, arrays, and error values to and from Excel (technically, XLOPERs can contain 12 possible data types – if you are curious, here is some documentation on MSDN
).  Currently, several of the data types (i.e. the one that can be used to communicate a reference to and from Excel) are not big enough to support the dimensions of the bigger grid size in Excel 12.

To address this, Excel 12 will implement a new XLOPER – which will be called something like XLOPER12 – which will have a larger reference (xltypeRef) data type and a larger array (xltypeMulti) data type which will support the entire big grid.  In addition, XLOPER12 will support Unicode data and therefore strings larger than 255 characters.  One happy by-product of the support for more characters is that XLLs written using XLOPER12 will be able to support 255 arguments, the same limit supported by Excel 12.

The Excel12 function
In order to use XLOPER12, developers will need to use a new C API function – Excel12 – instead of the existing Excel4 function.  Excel12 is essentially the same function updated to handle the new XLOPER12, so if developers want to take advantage of any of the changes described above, they will need to update their code to call the new API.  Note that existing code will continue to run as it always has, so developers will not face no backwards compatibility problems.

Updating XLL’s to take advantage of multi-threaded calculation
As discussed in a previous post
, Excel 12 will support multi-threaded calculation.  Since performance is very important for the bulk of XLL authors, we wanted to give developers who write UDFs using XLLs a way to allow their XLLs to participate in multi-threaded calculation (meaning Excel would calc multiple UDFs at once thereby improving calculation times). 

To do so, XLL authors need to do two things.  First, (the harder part) they need to make sure their XLL UDF (the code they wrote) is threadsafe (i.e. it must not make any non-thread-safe callbacks into Excel).  Second, they need to make a minor update to their XLL to tell Excel 12 it is threadsafe.  This is done in pretty much the same way that an XLL author would tell Excel that their function is volatile – by adding a special character to the “type text” entry in an XLL’s function table (the type text entry defines the data types for the functions’ return value and arguments). 

Specifically, to indicate that an XLL function is safe for multi-threaded calculation, an XLL author needs to add a "$" to the type text entry in an XLL’s function table … so the type text entry for a UDF that had one argument would look like this “ RR$”.  If this character is present, Excel will allow the UDF to participate in muti-threaded calc, just like Excel’s intrinsic functions; if the flag is absent, the reverse is true – all calls to that UDF will be run on a single thread.  Note, the Excel4 API will also respond appropriately to the “$” character, so if an XLL author wants to take advantage of multi-threading, but doesn't care about the big grid, they do not have to use the Excel12 API.

Published Tuesday, January 03, 2006 2:48 PM by David Gainer

Comments

# re: Quick detour #3: Updates we have made to XLLs

Tuesday, January 03, 2006 6:45 PM by PatriotB
XLOPER - short for Excel Developer, or Excel Operator?

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 12:04 AM by Biff
David,

Is it possible for you to change the appearance of the links you use in this blog?

They are very hard to distinguish from the normal text. At least, to these old eyes!

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 12:24 AM by David Gainer
PatriotB - I am actually not sure.

Biff - I changed the colour scheme. The links now appear to be orange. Is that better?

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 12:25 AM by Biff
Wow!

That was fast!

Thank you very much!

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 2:33 AM by Rob van Gelder
XL10 brought us COM add-ins (Automation Add-Ins). Will XL12 bring us similar for .NET?

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 4:50 AM by ross
arrrrrrrrrr!!!
change it back, i feel ill!!!!!!!!!

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 04, 2006 7:04 AM by Helen
Somewhat off-topic: where can I find documentation / resources about developing XLLs?

# re: Quick detour #3: Updates we have made to XLLs

Thursday, January 05, 2006 8:05 AM by XL-Dennis
David,

Looks promising and in general I believe it's important to make the official documentation more available when it comes to XLL.

Helen,
Check out the following KB-articles:
How To Build an Add-in (XLL) for Excel Using Visual C++
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q178474

The book "Excel add-in development in C/C++" (Steve Dalton / ISBN 0-470-02469-0 /

Rob,
Check out the following blogpost from Eric Carter
http://blogs.msdn.com/eric_carter/archive/2004/12/01/273127.aspx

Kind regards,
Dennis

# re: Quick detour #3: Updates we have made to XLLs

Thursday, January 05, 2006 12:04 PM by ross
Dave does this:

"Note, the Excel4 API will also respond appropriately to the “$” character, so if an XLL author wants to take advantage of multi-threading, but doesn't care about the big grid, they do not have to use the Excel12 API."

so excel 97 support multi threading???

# re: Quick detour #3: Updates we have made to XLLs

Thursday, January 05, 2006 12:30 PM by Steve Dalton
Hi David, thanks for the update. This is really exciting stuff. In relation to the comment "... they need to make sure their XLL UDF ... is threadsafe (i.e. it must not make any non-thread-safe callbacks into Excel)". Presumably calls to either Excel4 and Excel12 will be considered safe, yes? What about calls via COM? When can we get a look at the new xloper12 structure and the prototypes for the Excel12 function (or functions?) so that we can start working on our code?

Looking forward to the next post.

Steve

# re: Quick detour #3: Updates we have made to XLLs

Thursday, January 05, 2006 2:24 PM by Jim
David,
It's good to see at least one Office 12 blogger is actually updating their blog. Just wanted to say I appreciate the information you're providing. Perhaps you can raise the alarm to the other O12 bloggers that we (the beta testers) are reading the blogs. I'm particularly interested in Sharepoint and have not seen updates in those blogs for months.

Keep up the good work...you're putting the other bloggers to shame!

--Jim

# re: Quick detour #3: Updates we have made to XLLs

Thursday, January 05, 2006 8:52 PM by David Gainer
Hi all

Rob – no change to .NET support on the client, but I will talk about our model for the server in a future post.

Ross – sorry, we’re sticking with orange. Even I appreciate the bolder links :-). Also, sorry, no, Excel 97 does not support multi-threading. I can see what I wrote was confusing. What I meant was that if you had some XLLs that you have been using for some versions that you want to participate in mult-threaded calc, you can recompile them after adding the flag and they will work – you don’t need to update anything to use the Excel12 API. Is that clearer?

XL-Dennis – thanks for beating me to the punch wrt doc suggestions … we will update the XLL docs for v12.

Steve – we are still finalizing a few details, so I will have to hold off on further details about the new structure till then. Let me check about your other questions – I want to make sure I give you the right answer. Will post another comment when I am sure of all the details.

Jim – glad you are finding this useful. It is fun to talk about what we are doing.

# re: Quick detour #3: Updates we have made to XLLs

Friday, January 06, 2006 2:16 PM by ross
David, Thank you for replying!

Yes I've got it. Thank you. I'm getting use to the orange :-)


# re: Quick detour #3: Updates we have made to XLLs

Tuesday, January 10, 2006 9:42 AM by Len Holgate
Following up on the multi-threading type text "$"...

Will the XLL need to determine if it's running in Excel12 for the use of "$" to be valid or is $ ignored by all previous versions of excel when passed as part of the type string to a call to xlfRegister?

If the XLL does need to know (and therefore mustn't pass $ as part of a type string to earlier versions of excel) how can it find out at the point when xlAutoOpen() is called?

I've just done a test with Excel 2003 and it seems to ignore the a $ (I'd just like to be sure that all previous, no longer supported but still alive in the wild, versions of Excel will do likewise...)

# re: Quick detour #3: Updates we have made to XLLs

Tuesday, January 10, 2006 12:15 PM by Gary Mann
Does the new XLOPER12 data structure support a date type? The biggest issue for me with the old XLOPER (other than the 255 char strings) is the fact that dates are passed as xltypeNum. This makes it really hard to convert incoming data from the spreadsheet into your DLL-specific representation in a generic manner, unless you've got some form of internal metadata available as a hint.

Gary

# re: Quick detour #3: Updates we have made to XLLs

Wednesday, January 11, 2006 2:46 PM by David Gainer
Hi folks - good questions. If any of you are interested in providing detailed feedback on the changes we are planning, please send me an email using the "Contact" link above, and I will get in touch with you.

Steve, Certain calls to Excel4 and Excel12 are threadsafe, and certain ones are not. Docs will include a full list. Also, calls into Excel via COM do not participate in the multi-threaded calculation thus Excel does not run checks to see if they are thread-safe or not.

Len, using the $ function will cause a function fail to register in current versions of Excel. We are thinking about options we can give developers - one would be to call xlfGetWorkspace(2) to get the Excel version which would allow you to know if MTR was supported in that version of Excel.

Gary, no, there are no plans to have a date type.

# Methods In Excel » XLL update

Monday, February 20, 2006 6:58 PM by Methods In Excel » XLL update

# Excel 2007 investments in UDFs #1

Wednesday, May 03, 2006 9:32 AM by Microsoft Excel 2007 (nee Excel 12)
For the next few posts, we have a “guest post” from Danny Khen, a program manager on the Excel Services...

# Coding the markets » Blog Archive » Excel 12

Friday, June 09, 2006 4:16 AM by Coding the markets » Blog Archive » Excel 12

# Developing XLLs in Excel 2007

Tuesday, September 19, 2006 5:43 PM by Microsoft Excel 2007 (nee Excel 12)
Back in January I talked about updates we have made to XLLs.  We will soon be publishing an extensive...

# Developing XLLs in Excel 2007

Wednesday, October 04, 2006 5:45 PM by Microsoft Excel 2007 (nee Excel 12)

Back in January I talked about updates we have made to XLLs . We will soon be publishing an extensive

New Comments to this post are disabled
 
Page view tracker