【XLL API 函数】 xlFree

用于释放使用 Excel4,Excel4v,Excel12,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 被释放。到 Excel 2003 为止,最大指针数量只能为30个。在Excel 2007 只能为 255。

属性值/返回值

这个函数不返回值

备注

你必需释放 XLOPERXLOPER12 ,如果它们是 xltypeStr,xltypeMulti 或 xltypeRef 中的一种。它总是能安全的释放内存空间,即便你实际上没有使用内存,只要你是从 Excel4 或 Excel12 获取的这些数据。

你获取一个 XLOPER/XLOPER12 指针,它包含了Excel分配的内存,你就必需设置 xlbitXLFree 确保 Excel 释放这个内存资源。

实例

This example calls GET.WORKSPACE(1) to return the platform on which Excel is currently running as a string. The code copies this returned string into a buffer for later use. The code places the buffer back into the XLOPER12 for later use with the Excel function. Finally, the code displays the string in an alert box.

\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;
}

转载于:https://www.cnblogs.com/boluoke/p/5967328.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值