The newest new old thing

Apologies to Raymond Chen: https://blogs.msdn.microsoft.com/oldnewthing/
Against my better judgement I rewrote the xll add-in library. Again.
https://github.com/keithalewis/xll12
Still learning all the new C++11/14/17 good bits. And trying to avoid the crazy things that seem to be slipping into the latest standards.
No disrespect to women, but I always feel like I’m giving birth every time I try this. The ancient C Excel SDK has its, um, personality. I continue to be floored by how expressive modern C++ has become.
The AddIn class now uses lambda expressions to Register and Unregister on xlAutoOpen and xlAutoClose.
https://github.com/keithalewis/xll12/blob/master/xll/addin.h
You could probably save a few characters if you wrote this in python/ruby/perl/language du jour, except you can’t write this in those languages. It definitely takes more brain cells to come up with code this tight, but that is where the fun is.

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to The newest new old thing

  1. I was trying to use your old version of this and saw you’re working on a new version. I can open the project in the VS2015, but what do I need to do to install it so I can create Excel Add Ins using it?

  2. cecgeology says:

    I like the new version, there is some kind of elegance to the coding that is pleasing.
    What I can’t seem to do is get at values passed in as a range from excel to the xll. (most likely this is because I come from plain C in embedded micro controllers and I am missing things). Any pointers () would be appreciated. I dug around a lot of your related projects using the FP class and that I can do, but I was hoping to use a non contiguous range of cells as an input.

    • kalx says:

      Thanks, this is a labor of love for me. I only wish I had more time to add some more cool stuff I’ve been thinking about.

      It is possible to write functions that use a non contiguous range of cells as an input, but you will have two problems:
      1) Do you know how to select multiple range inputs in Excel?
      2) Do you understand the xltypeRef OPER(12)?
      Please don’t ask me to encourage you to do this.

      The FP(12) datatype gives you a pointer to a 2-d array of IEEE 64-bit doubles. No need to copy the array to any of your functions, just hand them the pointer. See, e.g., http://xlllapack.codeplex.com/

      The OPER(12) datatype gives you a pointer to an Excel cell or 2-d range of cells. Each cell is 24-bytes instead of 8-bytes, IIRC. Use this if you need booleans, (counted) string pointers, error types, etc.

      The old http://xll.codeplex.com/wikipage?title=User link has some documentation for both of these.

  3. cecgeology says:

    Thanks for the detailed reply.
    I re-read Dalton’s section on opers and found some silliness where somewhere along the line I confused what I was registering and passing — if I choose XLL_LPOPER in the addin registration function and then XLOPER12 in the function definition then i get the reference passed as an xltypeMulti from which I readily can access the values, provided its a contiguous range (i had chosen XLL_LPXLOPER type U before at some point and that was giving me xltypeSRef which was the source of my grief)
    To simplify things i will deal with the data in Excel first to get it into nice arrays and take advantage of the FP(12) datatype.

  4. kalx says:

    That will be simpler and more performant. I’ve never figured out a good way to ensure what users specify in AddIn as C arguments get type checked in the argument list to the actual call. LPOPERs get coerced to values by Excel. LPXLOPERs are references that you have to dig through.
    Don’t forget Excel is a functional language. One of the first and best at what Excel does.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s