Platform SDK: Fax Services

FaxInitializeEventQueue

The FaxInitializeEventQueue function creates a fax event queue for the calling fax client application. The queue enables the application to receive notifications of asynchronous events from the fax server. An application can specify how the fax server should inform the client application of events. The application can request that the fax server queue I/O completion packets to an I/O completion port, or it can specify notification messages.

BOOL WINAPI FaxInitializeEventQueue(
  HANDLE FaxHandle,        // handle to the fax server
  HANDLE CompletionPort,   // handle to an I/O completion port
  ULONG_PTR CompletionKey, // completion key value
  HWND hWnd,               // handle to the notification window
  UINT MessageStart        // window message base event number
);

Parameters

FaxHandle
[in] Specifies a fax server handle returned by a call to the FaxConnectFaxServer function.
CompletionPort
[in] Specifies a valid handle to an I/O completion port returned by a call to the CreateIOCompletionPort function. This parameter is required for notification using I/O completion packets. This parameter must be NULL if you specify notification messages.

For information about I/O completion ports, see I/O Completion Ports.

CompletionKey
[in] Specifies a variable that contains a completion key value the fax server includes in each I/O completion packet. This parameter is required for notification using I/O completion packets. This parameter must be NULL if you specify notification messages. For more information, see the following Remarks section.
hWnd
[in] Handle to a window of the fax client application to notify when an asynchronous event occurs. This parameter is required for notification messages. This parameter must be NULL if you specify notification using I/O completion packets.
MessageStart
[in] Specifies an unsigned integer that identifies the application's base window message. The application can use this number to determine whether to process the message as a fax server event. For more information, see the FAX_EVENT topic.

This parameter is required for notification messages. This parameter must be equal to zero if you specify notification using I/O completion packets.

Return Values

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError can return one of the following errors.

Error code Description
ERROR_INVALID_PARAMETER Both the hWnd and CompletionPort parameters are NULL, or both parameters are specified.
ERROR_INVALID_PARAMETER The FaxHandle parameter is NULL; or the hWnd parameter is specified but the FaxHandle parameter does not specify a connection with a local fax server; or the MessageStart parameter specifies a message in the range below WM_USER.
ERROR_INVALID_DATA The application called the FaxInitializeEventQueue function more than once during a fax service session.
ERROR_NOT_ENOUGH_MEMORY An error occurred during memory allocation.

Remarks

A fax client application must call the FaxInitializeEventQueue function before calling GetQueuedCompletionStatus to retrieve the value to specify in the CompletionKey parameter. This value is useful to a message loop that retrieves I/O completion packets from multiple I/O completion ports, using calls to the WaitForMultipleObjects function. If you specify a different completion key for each I/O completion port, you can identify the completion port associated with the completion packet.

An application can call the GetQueuedCompletionStatus function to retrieve the queued I/O completion packet for a completed I/O operation. A call to GetQueuedCompletionStatus also returns a pointer to a variable that the function sets to the address of a FAX_EVENT structure. The structure is associated with the I/O completion packet of interest. Call the LocalFree function to free the memory allocated for the FAX_EVENT structure.

After a fax client application receives the FEI_FAXSVC_ENDED message, it will no longer receive fax events from the fax service. To resume receiving fax events, the application must call the FaxInitializeEventQueue function again when the fax service restarts. The application can determine if the fax service is running by using the service control manager. For more information, see FaxClose and Enabling an Application to Receive Notifications of Fax Events.

For a list of the asynchronous events that can occur within the fax server, see the FAX_EVENT topic.

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Requires Windows 95 or later. Available as a redistributable with BackOffice Small Business Server.
  Header: Declared in Winfax.h.
  Library: Included as a resource in Winfax.dll.
  Unicode: Implemented as Unicode and ANSI versions on all platforms.

See Also

Fax Service Client Application Programming Interface Overview, Fax Service Client API Functions, FaxConnectFaxServer, FaxOpenPort, FaxClose, CreateIOCompletionPort, GetQueuedCompletionStatus, WaitForMultipleObjects, FAX_EVENT, LocalFree