The following function allows the faxing of files (.doc, .rtf, .txt, etc.) from within a PB program running under Windows 2000 Professional or Windows XP using the FaxCOM interface.
Note that the FaxCOM type library is required (available by using PB's COM browser or José Roca's excellent TypeLib Browser). The host machine must have a fax/modem card installed and working.
Note that the FaxCOM type library is required (available by using PB's COM browser or José Roca's excellent TypeLib Browser). The host machine must have a fax/modem card installed and working.
Code:
' *************************************************************************************************** ' Sending a Fax from within a PB program via COM ' *************************************************************************************************** ' ' This procedure requires a properly installed and working fax/modem card in the local machine. ' It also makes use of José Roca's indispensable TypeLib program for creating the necessary ' FaxCOM.inc file. ' ' The interface can send the contents of a designated file (the "docfile$") provided the file ' suffix is one that has been registered with Windows (such as .doc, .txt, .rtf, etc.). In other ' words, Windows needs to know how to handle the document type in order to fax it. ' ' The document file must be fully qualified (e.g.: "C:\Local Documents\Fax\FaxDoc1.rtf") ' ' According to MSDN documentation, this particular COM solution works under Windows 2000 Pro and ' Windows XP. It has not been tested on Windows Vista. It SHOULD work on any machine with the ' FaxCom 1.0 Type Library installed (but not guaranteed). ' ' Thanks to José Roca for his assistance in developing this routine. #INCLUDE "FaxCOM.inc" ' Fax COM Interface ' Generated by TypeLib 2.05 ' Library name: FAXCOMLib ' faxcom 1.0 Type Library ' --------------------------------------------------------------------------------------------------- FUNCTION SendFaxDocument&(docfile$, _ ' Qualified path and file name of document to fax recipient$, _ ' Name of recipient faxnumber$, _ ' Recipient's fax number yourfax$, _ ' Your fax number retries&) ' Number of times to retry LOCAL r&, thismachine$, result& LOCAL oFaxServe AS DISPATCH LOCAL oFaxDoc AS DISPATCH LOCAL vHost AS VARIANT LOCAL vDoc AS VARIANT LOCAL vObj AS VARIANT LOCAL vRetries AS VARIANT LOCAL vFaxNumber AS VARIANT LOCAL vRecipient AS VARIANT LOCAL vTSID AS VARIANT IF LEN(DIR$(docfile$)) = 0 OR _ LEN(faxnumber$) = 0 OR _ LEN(yourfax$) = 0 THEN EXIT FUNCTION END IF LET oFaxServe = NEW DISPATCH IN $PROGID_FaxServerFaxServer1 ' Create the interface IF ISTRUE ISOBJECT(oFaxServe) THEN ' Object created successfully HOST NAME TO thismachine$ ' Get host name LET vHost = thismachine$ ' Assign to variant OBJECT CALL oFaxServe.CONNECT(vHost) ' Connect to server LET vRetries = retries& ' Set number of retries OBJECT LET oFaxServe.Retries = vRetries LET vDoc = docfile$ ' Assign document to variant OBJECT CALL oFaxServe.CreateDocument(vDoc) TO vObj ' Set up document interface LET oFaxDoc = vObj ' Create FaxDox dispatch IF ISTRUE ISOBJECT(oFaxDoc) THEN ' Dispatch created OK LET vFaxNumber = REMOVE$(faxnumber$, "-") ' Remove any dashes OBJECT LET oFaxDoc.FaxNumber = vFaxNumber ' Assign to interface LET vRecipient = recipient$ ' Recipient's name OBJECT LET oFaxDoc.RecipientName = vRecipient ' Assign to interface LET vTSID = yourfax$ ' Sender's fax number OBJECT LET oFaxDoc.TSID = vTSID ' Assign sender's fax number OBJECT CALL oFaxDoc.SEND ' Send the fax LET oFaxDoc = NOTHING ' Close the dispatch result& = %TRUE ' Signal success END IF OBJECT CALL oFaxServe.Disconnect ' Disconnect the server LET oFaxServe = NOTHING ' Close the interface ELSE ' Fax server connection failed MSGBOX "Fax/modem not installed or not working properly.", _ ' Alert user %MB_OK, "Unable to Connect" END IF FUNCTION = result& ' Return result END FUNCTION ' // SendFaxDocument ' ---------------------------------------------------------------------------------------------------
Comment