xlFree

适用于:Excel 2013 | Office 2013 | Visual Studio

用于释放 Microsoft Excel 在调用 Excel4、Excel4vExcel12 或 Excel12v 时创建返回值 XLOPER/ XLOPER12分配的内存资源。 xlFree 函数释放辅助内存并重置指向 NULL 的指针,但不销毁 XLOPER/ XLOPER12的其他部分。

Excel4(xlFree, 0, n, LPXLOPER px_1, ..., LPXLOPER px_n);
Excel12(xlFree, 0, n, LPXLOPER12 px_1, ..., LPXLOPER12 px_n);

参数

px_1、...、px_n

要释放的一个或多个 XLOPER/ XLOPER12。 在 2003 之前的 Excel 版本中,可传递的最大指针数为 30。 从 Excel 2007 开始,此值将增加到 255。

属性值/返回值

此函数不返回值。

备注

必须释放从 Excel4 或 Excel4v 获取的每个 XLOPER 作为返回值,以及从 Excel12 或 Excel12v 获取作为返回值的每个XLOPER12(如果它们是以下类型之一):xltypeStrxltypeMultixltypeRef 只要你从 Excel4Excel12 中获取它们,即使它们不使用辅助内存,也始终可以安全地释放其他类型。

在返回到 Excel 时,指向 XLOPER XLOPER12的指针(该 XLOPER/ XLOPER12 仍包含要释放的 Excel 分配的内存),必须设置 xlbitXLFree 以确保 Excel 释放内存。

示例

此示例调用 GET。WORKSPACE (1) 返回 Excel 当前作为字符串运行的平台。 代码将此返回的字符串复制到缓冲区供以后使用。 代码将缓冲区重新放入 XLOPER12 ,以便以后与 Excel 函数一起使用。 最后,代码在警报框中显示字符串。

\SAMPLES\EXAMPLE\EXAMPLE.C

short WINAPI xlFreeExample(void)
{
   XLOPER12 xRes, xInt;
   XCHAR buffer[cchMaxStz];
   int i,len;
   // Create an XLOPER12 for the argument to Getworkspace.
   xInt.xltype = xltypeInt;
   xInt.val.w = 1;
   // Call GetWorkspace.
   Excel12f(xlfGetWorkspace, &xRes, 1, (LPXLOPER12)&xInt);
   
   // Get the length of the returned string
   len = (int)xRes.val.str[0];
   //Take into account 1st char, which contains the length
   //and the null terminator. Truncate if necessary to fit
   //buffer.
   if (len > cchMaxStz - 2)
      len = cchMaxStz - 2;
   // Copy to buffer.
   for(i = 1; i <= len; i++)
      buffer[i] = xRes.val.str[i];
   // Null terminate, Not necessary but a good idea.
   buffer[len] = '\0';
   buffer[0] = len;
   // Free the string returned from Excel.
   Excel12f(xlFree, 0, 1, &xRes);
   // Create a new string XLOPER12 for the alert.
   xRes.xltype = xltypeStr;
   xRes.val.str = buffer;
   // Show the alert.
   Excel12f(xlcAlert, 0, 1, (LPXLOPER12)&xRes);
   return 1;
}

另请参阅