PenDataToBuffer

2.0

Writes the data in an existing HPENDATA object to a serial buffer.

LONG PenDataToBuffer( HPENDATA hpndt, LPBYTE lpBuffer, LONG cbBuf, LPDWORD lpdwState )

Parameters

hpndt

Handle to the HPENDATA object.

lpBuffer

Pointer to an empty buffer.

cbBuf

Size of the buffer in bytes. The buffer 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 HPENDATA object. To read all data from the object in this case, the application must call PenDataToBuffer successively, each time copying the data from the buffer that lpBuffer points to before the next call. The example below illustrates this technique by writing an HPENDATA object in cbBuf increments to a file.

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 PenDataToBuffer. Between successive calls to PenDataToBuffer, the application must not alter the value that lpdwState points to. lpdwState can be NULL to signify that the buffer is large enough to contain the entire HPENDATA object. This implies that subsequent calls to PenDataToBuffer are not necessary.

Return Value

If successful, PenDataToBuffer returns the number of bytes transferred into 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 until the final transfer, when it is typically some smaller value. 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 other unspecified error.
PDR_MEMERR
Memory error.
PDR_PNDTERR
Invalid HPENDATA object.
PDR_VERSIONERR
Could not convert old HPENDATA object.

Comments

The buffer need not be large enough to accommodate the entire HPENDATA object. To allocate a buffer large enough for a single transfer, the application can determine the required size with the GetPenDataAttributes subfunction GPA_SIZE .

Example

The following example shows how to save an HPENDATA object to a file (hfile) that has already been opened for writing. The length of the pen data is saved in the file before writing the pen data itself:

#define cbBufMax 1024

BOOL NEAR PASCAL WritePenData( HFILE hfile, HPENDATA hpndt )

{

BYTE lpbBuf[cbBufMax];

DWORD dwState = 0L; // Must initialize to zero

LONG cb;

LONG cbSize;

if (!hfile || !hpndt)

return FALSE;

// Get size and save to file

if (GetPenDataAttributes(hpndt, (LPVOID)&cbSize, GPA_SIZE) < 0)

return FALSE;

// write size of pen data to file so that it can be used while reading it back

if (_lwrite(hfile, &cbSize, sizeof(LONG)) == HFILE_ERROR)

return FALSE;

// Write the pen data in chunks, and repeat until done

while ((cb = PenDataToBuffer(hpndt, lpbBuf,

cbBufMax, &dwState )) > 0L)

{

if (_lwrite( hfile, lpbBuf, (UINT)cb ) == HFILE_ERROR)

return FALSE;

}

return (cb >= 0L); // Return TRUE if cb >= 0

}

See Also

PenDataFromBuffer

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database