PenDataFromBuffer
2.0
Creates a HPENDATA
object from serial data in a buffer. The buffer must have been previously
written by the PenDataToBuffer
LONG PenDataFromBuffer( LPHPENDATA lphpndt,
UINT gmemFlags, LPBYTE lpBuffer, LONG cbBuf,
LPDWORD lpdwState )
Parameters
lphpndt
Pointer to an
uninitialized HPENDATA handle. If PenDataFromBuffer returns
successfully, lphpndt points to a new HPENDATA object containing
a copy of the serial points.
gmemFlags
Flag that
specifies whether or not the Windows GlobalAlloc
lpBuffer
Pointer to a
byte buffer containing serial data.
cbBuf
Size of the
buffer, which must be at least 64 bytes in size. If the buffer serves as an
intermediate holding area, it need not be as large as the final HPENDATA
object. To create the object, the application must call PenDataFromBuffer
successively, each time reading a new section of data into the buffer that lpBuffer
points to before the call. The example below illustrates this technique by
filling an HPENDATA object in stages, reading data from a file in cbBuf
increments.
lpdwState
Address of a
DWORD variable used by the system to maintain the transfer state. The DWORD
variable must be initialized to 0 before the first call to PenDataFromBuffer.
Between successive calls to PenDataFromBuffer, the application must not
alter the value that lpdwState points to. lpdwState can be NULL
to signify that the buffer contains the entire data set for the HPENDATA
object. This implies that subsequent calls to PenDataFromBuffer are not
necessary.
Return Value
If
successful, PenDataFromBuffer returns the number of bytes transferred
from the buffer. If the size of the pen data is larger than the buffer, the
return value is equal to the buffer size passed in cbBuf. A value of 0
indicates no more data to transfer. If there is an error, one of the following
negative values is returned:
Constant |
Description |
PDR_ERROR |
Parameter
or overflow error. |
PDR_MEMERR |
Memory
error. |
Comments
The data
being provided by the application must have been previously written by the PenDataToBuffer
PenDataFromBuffer creates an HPENDATA object and provides a
handle to it. The application must destroy the object when finished. The lphpndt
argument points to a valid HPENDATA handle only if the function returns
PDR_OK.
While this
function is reconstituting the HPENDATA object, the application must not
attempt to use it in any way because it will be invalid until the last buffer
is read.
Example
The following
example shows how to create a HPENDATA object from a file (hfile)
that has already been opened for reading. Before reading the pen data, its
length is retrieved from the file:
#define cbBufMax 1024
HPENDATA NEAR PASCAL ReadPenData( HFILE hfile )
{
HPENDATA hpndt = NULL;
LONG cb, cbRead, cbHpndt;
BYTE lpbBuf[cbBufMax]; // Buffer
DWORD dwState = 0L; // Must initialize to 0
if (!hfile
||
(cb = _lread(hfile, &cbHpndt, sizeof(DWORD))) == HFILE_ERROR
||
cb != sizeof(LONG))
return
NULL;
while
(cbHpndt > 0)
{
if
((cbRead = _lread( hfile, lpbBuf, min(cbHpndt, cbBufMax )))
==
HFILE_ERROR
||
PenDataFromBuffer( &hpndt, 0, lpbBuf,
cbBufMax, &dwState ) < 0)
{
if
(hpndt)
DestroyPenData(
hpndt );
return NULL;
}
cbHpndt
-= cbRead;
}
return
hpndt;
}
See Also