TAILIEUCHUNG - Financial Applications Using Excel Add-in Development in C/C++Second Edition phần 5

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. 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 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 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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.