Financial Applications using Excel Add-in Development in C/C++ phần 5

Sau khi trở về từ chức năng này, các DLL sẽ nhận được một cuộc gọi đến việc thực hiện của xlAutoFree, vì nó đã trở lại một xloper. xlAutoFree sẽ nhận được địa chỉ của p_ret_val trong trường hợp này. Mã cho chức năng đó sẽ phát hiện rằng loại là xltypeMulti | 210 Excel Add-in Development in C C After returning from this function the DLL will receive a call to its implementation of xlAutoFree since it has returned an xloper. xlAutoFree will receive the address of p_ret_val in this case. The code for that function should detect that the type is xltypeMulti and should check that each of the elements themselves do not need to be freed which they don t in this example . Then it should free the xloper array memory. The following code does the same thing but using the cpp_xloper class introduced in section on page 146. The code is simplified but the same things are happening - just hidden within the class. xloper __stdcall random_array int rows int columns cpp_xloper array RW rows COL columns if xltypeMulti return NULL DWORD array_size array_size cpp_xloper ArrayElt for DWORD i 0 i array_size i if i ArrayElt xlfRand i ArrayElt return Note again that the line xlfRand could be replaced with a faster-to-call internal function. See optimisation note above . The cpp_xloper class contains a method for returning a thread-safe copy of the contained xloper ExtractXloper . This method sets the xlbitDLLFree bit for types where the DLL has allocated memory. Here is a listing of the code for ExtractXloper . Return the xloper as a pointer to a thread-local static xloper. This method should be called when returning an xloper to an Excel worksheet function and is thread-safe. xloper cpp_xloper ExtractXloper void Get a thread-local persistent xloper xloper p_ret_val get_thread_local_xloper if p_ret_val Could not get a thread-local copy return NULL if gExcelVersion12plus cast down to an xloper FreeOp xloper12_to_xloper m_Op m_Op12 m_DLLtoFree true ensure bits get set later in this fn FreeOp12 Memory Management 211 p_ret_val m_Op Make a shallow copy of data and pointers if xltypeRef xltypeMulti xltypeStr 0 No need

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.