PRB: Can not get status of a Fax Job with Fax Service. RRS feed

  • Question


    PRB: Can not get status of a Fax Job with Fax Service.


    Please help,


    First off, I'm not sure if this is the correct forum to use.


    I'm trying to programmatically send faxes using Microsoft's built in Fax Service, on XP, 2003, and later products. I have found the "Fax Service Extended COM" with such objects as IFaxDocument, and made a working sample to send a Fax. The code is below.


    My issues are as such:


    1) I must get the status of the fax being sent programmatically.

    2) I do not want any GUI shown.



    1) I must get the status of the fax being sent programmatically.

     - - - The code uses logic to get the status, but it always throws an exception as commented below. I do not want to use any Notify-Service thingy, unless it is 100% spoon fed to me, as frankly, it looks God aweful. I just want to know if the current fax I am trying to send is sent or not. Note, once the Submit (or ConnectedSubmit) fire off, the program returns asynchronously (as it should) while the fax is in the processing of being sent.


    If there is anyway to do this, with just a simple command line call, that would be awesome.


    2) I do not want any GUI shown.

     - - - When the Submit/ConnectedSubmit fire off, the GUI of whatever the "App" is shows. In my example, I used a PDF file, and it of course is associated to Adobe AcroRead. When the Submit fires, AcroRead launches, is plainly visible. And stays there! Then the GUI of the "Fax Console's Status" page pops up, and stays there.


    If you try to send a file that does not have an "app" associated to it, the Submit/ConnectedSubmit will fail, returning a COM error basically saying there is no "app" associated to it. What this means to me, is that the COM Interface is basically relying on the "app" to do perhaps a "File Print" to the Fax Server Printer, and that is terrible is true. Isn't there some way to programmatically send a fax to the Fax Service without invoking any other application?




    #define FAX_BODY L"C:\\Closet\\HKTQ_181342.pdf"

    #define MY_DOCUMENT L"My First Fax"

    #define RECIPIENT_PHONE_NUMBER L"9, 770-698-0170"

    #define RECIPIENT_NAME L"Bill"

    #define SENDER_NAME L"Bob"

    #define SENDER_CODE L"23A54"

    #define SENDER_DEPT L"Accts Payable"

    #define SENDER_PHONE_NUMBER L"+972 (4) 555-9070"


    FAXCOMEXLib::IFaxFolders *pIFaxFolders = NULL;

    FAXCOMEXLib::IFaxOutgoingQueue *pIFaxOutgoingQueue = NULL;

    FAXCOMEXLib::IFaxOutgoingJobs *pIFaxOutgoingJobs = NULL;

    FAXCOMEXLib::IFaxOutgoingJob *pIFaxOutgoingJob = NULL;




    HRESULT hr;

    FAXCOMEXLib::IFaxServerPtr sipFaxServer;

    FAXCOMEXLib::IFaxActivityPtr sipFaxActivity;

    FAXCOMEXLib::IFaxDocumentPtr sipFaxDocument;

    FAXCOMEXLib::IFaxFoldersPtr sipFaxFolders;

    FAXCOMEXLib::IFaxOutgoingQueuePtr sipFaxOutgoingQueue;

    FAXCOMEXLib::IFaxJobStatusPtr sipFaxJobStatusPtr;

    hr = sipFaxServer.CreateInstance("FaxComEx.FaxServer");



    hr = sipFaxDocument.CreateInstance("FaxComEx.FaxDocument");

    if (FAILED(hr))


    hr = sipFaxServer->Connect("");

    hr = sipFaxServer->get_Folders(&sipFaxFolders);

    sipFaxOutgoingQueue = sipFaxFolders->GetOutgoingQueue();

    sipFaxDocument->Body = FAX_BODY;

    sipFaxDocument->DocumentName = MY_DOCUMENT;

    hr = sipFaxDocument->Recipients->Add(RECIPIENT_PHONE_NUMBER, RECIPIENT_NAME);

    sipFaxDocument->Sender->Name = SENDER_NAME;

    sipFaxDocument->Sender->BillingCode = SENDER_CODE;

    sipFaxDocument->Sender->Department = SENDER_DEPT;

    sipFaxDocument->Sender->FaxNumber = SENDER_PHONE_NUMBER;

    _variant_t varJobID = sipFaxDocument->Submit((BSTR) NULL);

    // I have also tried this:


    // _variant_t varJobID = sipFaxDocument->ConnectedSubmit(sipFaxServer);


    // It also causes the GUI of the "app" to show, along with the GUI of the Fax status.

    long lIndex = 0;

    long lUBound;


    // Get the upper bound of the array or job IDs.


    SafeArrayGetUBound(varJobID.parray, 1, &lUBound);

    CString csJobID;

    BSTR bstrJobID;

    for (lIndex = 0; lIndex <= lUBound; lIndex++)


    SafeArrayGetElement(varJobID.parray , &lIndex, LPVOID(&bstrJobID));

    csJobID = bstrJobID;



    if (csJobID.IsEmpty())




    hr = sipFaxServer->get_Folders(&pIFaxFolders);



    hr = pIFaxFolders->get_OutgoingQueue(&pIFaxOutgoingQueue);



    __int64 i64JobId = _atoi64((LPSTR) (LPCSTR) csJobID);

    CString csHexJobId;

    csHexJobId.Format("%016I64x", i64JobId);

    _bstr_t _bstr_t_HexJobId;

    _bstr_t_HexJobId = (LPCSTR) csHexJobId;

    pIFaxOutgoingJob = pIFaxOutgoingQueue->GetFaxJob((BSTR) _bstr_t_HexJobId);



    // The following fails. Why?

    FAX_JOB_STATUS_ENUM_Temp = pIFaxOutgoingJob->GetStatus();

    // I have also tried this code below, and it fails the same way.


    //DWORD dwTemp = 0;

    //hr = pIFaxOutgoingJob->get_Status((FAXCOMEXLib::FAX_JOB_STATUS_ENUM *) &dwTemp);


    // _com_issue_error(hr);



    catch (_com_error& error)


    CString strErr = error.ErrorMessage();

    if(strErr.CompareNoCase(_T("The object indentifier does not represent a valid object.")) == 0)

    m_strErr.Format(_T("Fax Connect(), error, make certain the XP fax service component has been added, and that a local fax printer has been installed and configured."));


    m_strErr = error.ErrorMessage();


    if (pIFaxOutgoingJob)



    pIFaxOutgoingJob = NULL;


    if (pIFaxOutgoingJobs)



    pIFaxOutgoingJobs = NULL;


    if (pIFaxOutgoingQueue)



    pIFaxOutgoingQueue = NULL;


    if (pIFaxFolders)



    pIFaxFolders = NULL;






    Tuesday, November 25, 2008 6:21 PM

All replies