Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'excel add-in development in c/c++ applications in finance phần 3', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Using VBA 69 A VB interface function declared as taking a range argument would not be able to receive literal values from the worksheet. If this were not a problem then the VB code might look like this given that there is no need to call IsObject . Function VtFunction r As Range As Variant VtFunction C_vt_function r.Value End Function The following line would have resulted in a Variant of type VT_DISPATCH being passed to the DLL function. VtFunction C_vt_function r 3.7.3 Converting array Variants to and from C C types Array Variants are Variants that contain an array. The array itself is an OLE data type called the SafeArray declared as SAFEARRAY in the Windows header files. An understanding of the internal workings of the SAFEARRAY is not necessary to bridge between VB and C C . All that s required is a knowledge of some of the functions used to create them obtain handles to their data release data handles find out their size upper and lower bounds find out what data-type the array contains and finally destroy them. The key functions all accessible in C C via the header windows.h are SafeArrayCreate SafeArrayDestroy SafeArrayAccessData SafeArrayUnaccessData SafeArrayGetDim SafeArrayGetElemsize SafeArrayGetLBound SafeArrayGetUBound SafeArrayGetElement SafeArrayPutElement To convert an array Variant the C C DLL code needs to do the following Determine that the Variant is an array by testing its type for the VT_ARRAY bit. Determine the element type by masking the VT_ARRAY bit from its type. Determine the number of dimensions using the SafeArray cDims property or by using the SafeArrayGetDim function. Determine the size of the array using SafeArrayGetUBound and SafeAr-rayGetLBound for each dimension. Convert each array element from the possible Variant types that could originate from a worksheet cell to the desired data type s . 70 Excel Add-in Development in C C To create an array Variant the C C DLL code needs to do the following Call SafeArrayCreate having .