Learn to use SafeArray

xiaoxiao2021-03-06  110

It is also important to learn to use SafeArray because it is often used in ADO programming. Its main purpose is to pass the passage of array parameters in Automation. Because in a network environment, arrays cannot be delivered directly, but they must be packaged into safgonaray. Essentially SafeArray adds a descriptor to add a description of the usual array, indicating that its dimension, length, boundary, element type, etc. SafeArray is not used alone, but is then packaged in a variable of the Variant type, and then transfer it as a parameter. If the value of VT_Array | ..., it is a SafeArray that is packaged, it is a pointer to SafeArray. The type of element in SafeArray can be any type of Variant's encapsulation, including the Variant type itself. Use SafeArray specific steps: Method 1: Packing a SafeArray: (1). Define variables, such as: Variant Varchunk; SafeArray * PSA; SafeArrayBound Rgsabound [1]; (2). Create a SafeArray descriptor: uisread = f.read Bval, chunksize; // read array from a file. if (uisread == 0) Break; rgsabound [0] .CELEments = uisread; rgsabound [0] .llbound = 0; PSA = SafeArrayCreate (VT_UI1, 1, RGSABOUND) (3). Place the data element to SafeArray: for (long index = 0; Index

To read the data in SafeArray: (1). Read byte BUF [Lisread] with SafeArraygetElement; for (long index = 0; Index

This method reads and writes SafeArray, it can manipulate the SafeArray data buffer, which is fast than SafeArraygetElement and SafearrayPutelement. It is especially suitable for reading data. But don't forget to call :: SafeArrayunAccessData (PSA), otherwise it will be wrong.

转载请注明原文地址:https://www.9cbs.com/read-102317.html

New Post(0)