Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Ngoài ra còn có các vấn đề đảm bảo rằng một biến tĩnh được sử dụng như là một giá trị trả về từ một chức năng xuất khẩu (như trên) không nhận được viết bởi một thread gọi các chức năng tương tự trước khi người nhận giá trị trả về có thời gian để đọc nó. | Memory Management 207 xloper __stdcall xloper_memory_example int trigger static xloper dll_name Not thread-safe Excel4 xlGetName dll_name 0 Excel has allocated memory for the DLL name string which cannot be freed until after being returned so need to set this bit to tell Excel to free it once it has finished with it. dll_name.xltype xlbitXLFree return dll_name The cpp_xloper class contains a method for returning a thread-safe copy of the contained xloper or xloper12 xloper cpp_xloper ExtractXloper void xloper12 cpp_xloper ExtractXloper12 void These methods set the xlbitXLFree bit if the contained xloper xloper12 was populated in a call to the C API via one of the overloaded wrapper functions cpp_xloper Excel . See next section for a listing of the code for ExtractXloper . Note Setting xlbitXLFree on an xloper that is to be used for the return value for a call to Excel4 prior to the call to Excel4 that allocates it will have no effect. The correct time to set this bit is after the call that sets its value after it might be passed as an argument to other Excel4 calls before a pointer to it is returned to the worksheet. The following code will fail to ensure that the string allocated in the call to Excel4 gets freed properly as the type field of ret_oper is overwritten in the call xloper __stdcall bad_example1 void static xloper ret_oper Not thread-safe ret_oper.type xlbitXLFree Excel4 xlGetName ret_oper 0 return ret_oper Memory leak xlbitXLFree no longer set The following code will confuse the call to xlfLen which will not be able to determine the type of ret_oper correctly. xloper __stdcall bad_example2 void static xloper ret_oper Not thread-safe Excel4 xlGetName ret_oper 0 ret_oper.type xlbitXLFree xloper length Excel4 xlfLen length 1 ret_oper do something with the string s length. return ret_oper 208 Excel Add-in Development in C C The following code will work properly. xloper __stdcall good_example void static xloper ret_oper Not thread-safe Excel4 xlGetName .