Using Fax C++
Fax C++ is a software development kit from Black Ice Software that makes faxing easy for the programmer. It supports a very wide variety of fax modems such as boards manufactured by Brooktrout or Dialogic and - of course - the simple class 1-2 modems as well. Fax C++ offers a uniform interface to use all of the supported faxing modems in order to reduce the learning curve as much as possible.
This article will show a basic program that sends a picture file as a fax.
Using the ActiveX control
(Visual Basic .NET, C#, Delphi, Visual Basic 6.0, C++, FoxPro samples available)
Many developer environments support using ActiveX controls in a very easy manner – just click and add. ActiveX controls are also supported by internet browsers such as Internet Explorer, and JavaScript or VBScript can interact with them as well, so these controls can become very powerful website elements. Black Ice gives ActiveX controls in its SDKs.
Sending a fax can be accomplished by calling a short series a functions and setting some property values to the proper ones.
Firstly one should set the value of the FaxType property. This will decide what communication protocol will be used. For example “GCLASS1(SFC)” means a general Class 1 modem with software flow control.
Fax.FaxType = “GCLASS1(SFC)”
Then one needs to open a modem port to send the fax through. This can be done with the OpenPort function, passing the port’s name in a string. The port name can be: “COMX”, “BChannelX”, “DChannelX”, “GChannelX”; where X is the number of the port.
ret = Fax.OpenPort(“COM1”)
When the port is open, one should set the capabilities of it with the SetPortCapability function. (ECM is Error Correction Mode.) For example:
Fax.SetPortCapability(“COM1”, PC_ECM, True)
Fax.SetPortCapability(“COM1”, PC_BINARY, True)
Fax.SetPortCapability(“COM1”, PC_MAX_BAUD_SEND, 33600)
When the port’s ready, one has to create the fax objects to send through it. The function for that is CreateFaxObject.
faxid = Fax.CreateFaxObject(1 (monochrome), 1 (pages), 3, 2, 1, 2 (G3-1D), 2 (BFT), 3 (ECM), 2, 1)
The fax object is now created. Now one has to add the pages to send. The SetFaxPage function is used for that. Call this function for each page.
ret = Fax.SetFaxPage(faxid, 1, PAGE_FILE_UNKNOWN, 1)
The fax object is ready for sending after this. You can send the fax with SendNow or SendFaxObj. SendNow tries sending the fax instantly, and returns an error if the port is in use. SendFaxObj will use a queue system and send the fax on an available port.
ret = Fax.SendNow(“COM1”, faxid)
The fax sending will happen in the background. When it’s done, an EndSend event will be generated. This event is the best place to destroy the fax object in.
Fax.ClearFaxObject(faxid)
After a port will become free, a Terminate event will be generated. The port may be closed in this event.
ret = Fax.ClosePort(“COM1”)
Using the library
(C++ sample available)
You may also use the FaxCpp.dll for added performance. Using the DLL is slightly different than using the ActiveX control.
The main difference is that the fax manager DLL will send faxing events as windows messages to the application’s window that was provided through the SetFaxMessage function. You may catch these messages in the window’s message queue.
Unlike in the ActiveX control, the user has to initialize the DLL, while the ActiveX does that automatically. That can be done with the SetupFaxDriver function.
ret = SetupFaxDriver(“FaxMng.dll”)
The program will also need to uninitialize the driver with EndOfFaxDriver.
EndOfFaxDriver(False)
Otherwise, the DLL uses an interface mostly alike the ActiveX control’s interface.
For more information about this topic, please see the following links: