Platform SDK: Fax Services

Creating a Completion Packet

The sample code in this topic illustrates the procedure for creating an I/O completion packet and posting the packet to the fax service. Fax service providers must post I/O completion packets, in the form of a FAX_DEV_STATUS structure, to the fax service when the provider changes its status.

First, the sample computes the size required for the FAX_DEV_STATUS structure. It calls the HeapAlloc function to allocate the memory for the structure from the heap specified by the HeapHandle parameter of the FaxDevInitialize function. Then the sample assigns values to the members in the structure. Finally, the example calls the PostQueuedCompletionStatus function, using the CompletionPortHandle and CompletionKey parameters specified in the FaxDevStartJob function, to post the completion packet.

BOOL rVal;
DWORD StatusSize;
PFAX_DEV_STATUS FaxStatus;
 
 
//
// Compute the size of the status structure. 
//
 
StatusSize = 0;
 
//
// Allocate memory for the status structure. 
//
 
FaxStatus = (PFAX_DEV_STATUS) HeapAlloc( HeapHandle, HEAP_ZERO_MEMORY, StatusSize );
if (!FaxStatus) {
    //
    // Process some errors. 
    //
}
 
//
// Assign values to the status structure. 
//
 
FaxStatus->SizeOfStruct     = sizeof(FAX_DEV_STATUS);
FaxStatus->StatusId         = 0;
FaxStatus->StringId         = 0;
FaxStatus->PageCount        = 0;
FaxStatus->CSI              = NULL;
FaxStatus->CallerId         = NULL;
FaxStatus->RoutingInfo      = NULL;
FaxStatus->ErrorCode        = 0;
 
//
// Post the packet to the fax service. 
//
 
rVal = PostQueuedCompletionStatus(
    CompletionPortHandle,             // from FaxDevStartJob
    sizeof(FAX_DEV_STATUS),
    CompletionKey,                    // from FaxDevStartJob
    (LPOVERLAPPED) FaxStatus
    );
if (!rVal) {
    //
    // Process some errors. 
    //
}