適用於:Excel 2013 |Office 2013 |Visualstudio
用來傳回 UDF) (異步使用者定義函式的結果。
Excel12(xlAsyncReturn, LPXLOPER12 pxRes, 2, LPXLOPER12 pxAsyncHandle, LPXLOPER12 pxFunctionResult);
參數
pxAsyncHandle (xltypeBigData)
傳回結果之 UDF 的異步句柄。
pxFunctionResult
UDF 的傳回值。
屬性值/傳回值
如果成功, 會傳回 TRUE (xltypeBool) 。 如果不成功,則會 傳回 FALSE。
註解
xlAsyncReturn 是在重新計算期間,Excel 在非計算線程上允許的唯一回呼。 異步 UDF 的異步部分不得執行 xlAsyncReturn 以外的任何回呼。 XLL 必須釋放配置來保存傳回值的記憶體。
pxAsyncHandle 和 pxFunctionResult 參數在單一回呼中傳回句柄陣列和對應值時,也可以是 xltypeMulti 類型。 使用單一回呼時,傳遞指向XLOPER12結構的LPXLOPER12,該結構包含包含異步句柄和傳回值的一維數位列。 這些陣列的順序必須相同,Excel 才能正確比對異步句柄及其對應的值。
下列範例示範如何使用 xlAsyncReturn 進行批次呼叫。
int batchSize = 10;
LPXLOPER12 pHandles = new XLOPER12[batchSize];
LPXLOPER12 pValues = new XLOPER12[batchSize];
/*Add code to fill in LPXLOPER12 arrays (pHandles and pValues)
with the XOPER12 structures that contain the asynchronous handles
and values, in respective order*/
//Create an XLOPER12 of type xltypeMulti, and fill the Handle array
XLOPER12 handleArray;
handleArray.xltype = xltypeMulti;
handleArray.val.array.rows = 1;
handleArray.val.array.columns = (COL)batchSize;
handleArray.val.array.lparray = pHandles;
//Create an XLOPER12 if type xltypeMulti, and fill the Values array
XLOPER12 valueArray;
valueArray.xltype = xltypeMulti;
valueArray.val.array.rows = 1;
valueArray.val.array.columns = (COL)batchSize;
valueArray.val.array.lparray = pValues;
//Make the callback with the return value
int ret = Excel12(xlAsyncReturn, 0, 2, &handleArray, &valueArray);
//Add code to free the allocated memory here (pHandles, pValues, valueArray, handleArray)
return ret;