Question

FYI 1: UDF = User Defined (Worksheet) Function FYI 2: XLL = Excel add-in (DLL -> XLL)

I am writing an XLL add-in for Excel in C/C++ using the Excel4() API from Microsoft.
Link: http://msdn.microsoft.com/en-us/library/bb687835.aspx

I have a "complicated" task that I want to use multiple threads for better performance. While I understand that calculation in Excel 2003 is single threaded, I want to know if my UDF can (a) spawn threads to do work, (b) wait for the threads to finish, and (c) return the result.

To be very clear, I will not do any Excel automation nor call Excel4() in the threads.

Pseudo code:

Variant MyComplexUDF(Variant input1, Variant input2)
{
    Thread t1 = new WorkerThread(input1);
    Thread t2 = new WorkerThread(input2);
    t1.join();
    t2.join();
    return [t1.Result(), t2.Result()];
}

On the surface, this appears OK, but I am not an expert on DLLs/XLLs and threading.

P.S. I have searched Google (high and low) for this answer, and cannot find anything on the matter.

Was it helpful?

Solution

You can start as many threads as you want and then wait on them. There is also support for async UDF's in the latest version of the API. You can find some examples in http://xll.codeplex.com. Have a look at test/async.cpp: http://xll.codeplex.com/SourceControl/changeset/view/14528#139508

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top