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

Đoạn mã trên giả định rằng ngày đếm nối tiếp là những Excel cửa hàng khi sử dụng mặc định 1900 ngày của nó Nếu ứng dụng của bạn là cực kỳ quan phụ thuộc vào ngày, bạn nên kiểm tra tình trạng của thiết lập này và chuyển đổi tất cả các ngày đến và trở về. | Miscellaneous Topics 381 define MAX_COM_CMD_LEN 512 HRESULT OLE_RunXllCommand char cmd_name static DISPID dispid 0 VARIANTARG Command DISPPARAMS Params HRESULT hr wchar_t w MAX_COM_CMD_LEN 1 char cErr 64 int cmd_len strlen cmd_name if pExcelDisp cmd_name cmd_name cmd_len strlen cmd_name MAX_COM_CMD_LEN return S_FALSE try Convert the byte string into a wide char string. A simple C-style type cast would not work mbstowcs w cmd_name cmd_len 1 VT_BSTR SysAllocString w NULL Command 1 0 if dispid 0 wchar_t ucName L Run hr pExcelDisp- GetIDsOfNames IID_NULL ucName 1 LOCALE_SYSTEM_DEFAULT dispid if FAILED hr sprintf cErr Error hr 0x 08lx hr MessageBox NULL cErr GetIDsOfNames MB_OK MB_SETFOREGROUND SysFreeString return hr hr pExcelDisp- Invoke dispid IID_NULL LOCALE_SYSTEM_DEFAULT DISPATCH_METHOD Params NULL NULL NULL if FAILED hr sprintf cErr Error hr 0x 08lx hr MessageBox NULL cErr Invoke MB_OK MB_SETFOREGROUND SysFreeString return hr Success. catch _com_error ce 382 Excel Add-in Development in C C If COM throws an exception we end up here. Most probably we will get a useful description of the error. MessageBoxW NULL L Run mB_OK MB_SETFOREGROUND Get and display the error code in case the message wasn t helpful hr sprintf cErr Error hr 0x 08lx hr MessageBox NULL cErr The Error code MB_OK MB_SETFOREGROUND SysFreeString return hr Calling user-defined functions using COM This is achieved using the Run method exposed by Excel via the COM interface. There are some limitations on the exported XLL functions that can be called using COM the OLE Automation interface for Excel only accepts and returns Variants of types that this interface supports. It is not possible to pass or retrieve Variant equivalents of xloper types xltypeSRef xltypeRef xltypeMissing xltypeNil or xltypeFlow. Only types xltypeNum xltypeInt

Không thể tạo bản xem trước, hãy bấm tải xuống
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.