tailieunhanh - Excel add in development in c and c phần 4

Lưu ý: Nếu bộ nhớ đã được giao với các dòng mã sau đây, thay vì như trên, khối bộ nhớ sẽ là quá nhỏ, và sẽ bị tràn ngập khi các phần tử cuối cùng của mảng đã được giao. Ngoài ra, Excel sẽ hiểu sai tất cả các yếu tố của mảng, dẫn đến giá trị trả lại không thể đoán trước, số điểm không hợp lệ nổi, và tất cả các loại nghịch ngợm. | Passing Data between Excel and the DLL 109 Note If the memory were allocated with the following line of code instead of as above the memory block would be too small and would be overrun when the last element of the array was assigned. Also Excel would misread all the elements of the array leading to unpredictable return values invalid floating point numbers and all kinds of mischief. Incorrect allocation statement p_array xl_array malloc 2 sizeof WORD size sizeof double A related point is that it is not necessary to check both that a pointer to an xl_array and the address of the first data element are both valid or not NULL. If the pointer to the xl_array is valid then the address of the first element which is contained in the structure is also valid. Warning There is no way that a function that receives a pointer to an xl_array can check for itself that the size of the allocated memory is sufficient for all the elements implied by its rows and columns values. An incorrect allocation outside the DLL could cause Excel to crash. The next example modifies the passed-in array s values but not its shape or size. void __stdcall xl_array_example2 xl_array p_array if p_array p_array- rows p_array- columns p_array- columns 0x100 return int size p_array- rows p_array- columns for int i 0 i size i p_array- array i i The next example modifies the passed-in array s values and shape but not its size. void __stdcall xl_array_example3 xl_array p_array if p_array p_array- rows p_array- columns p_array- columns 0x100 return int size p_array- rows p_array- columns Change the shape of the array but not the size int temp p_array- rows p_array- rows p_array- columns p_array- columns temp Change the values in the array for int i 0 i size i p_array- array i 110 Excel Add-in Development in C C The next example modifies the passed-in array s values and reduces its size. void __stdcall xl_array_example4 xl_array p_array if p_array p_array- rows p_array- columns p_array- columns .

TỪ KHÓA LIÊN QUAN