Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API (faxcomex.dll)

  • Thread starter Thread starter PKenney
  • Start date Start date
P

PKenney

Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API
(faxcomex.dll)

Hello all,

I am having trouble retreiving the Fax Status using C#...

Also I can only seem to set FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM one at
a time...

I can see at run-time that I am Registering the
FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED Event

or which ever SINGLE FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM enum I
use...

And my fax works just fine with this code, but does not appear to be
correctly raising the FaxJobStatus events no matter which enum I use...

Am I missing something obvious?
Thanks in advance.

using System;

using System.IO;

using System.ComponentModel;

using System.Collections;

using System.Runtime.InteropServices;

using System.Diagnostics;

using System.Threading;

using FAXCOMEXLib;

namespace csFaxComponent

{

public class csFax

{

protected FAXCOMEXLib.FaxDocument objFaxDocument = new
FAXCOMEXLib.FaxDocumentClass();

protected FAXCOMEXLib.FaxServer objFaxServer;

protected object JobID;

public static void Main()

{

try

{

csFax objcsFax = new csFax();

string FileName;

objcsFax.objFaxServer = new FAXCOMEXLib.FaxServer();

objcsFax.objFaxServer.Connect("AFaxServer");

//Register for server Fax Job Status events, this method has a pointer to
the

//IFaxServerNotify Interface that implements the FaxJobStatus Class, that
enables the

//caller to receive dynamic status messages...

//You do not create the FaxJobStatus class directly it is received as part
of a

//notification when you implement "ListenToServerEvents"

//Having trouble with multicasting this enum, Microsoft has a VB 6 example
that does not appear to convert well to C#

objcsFax.objFaxServer.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED);

//
objcsFax.objFaxServer.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetOUT_QUEUE);

//E.G.: objFaxServer.ListenToServerEvents fsetFXSSVC_ENDED + fsetOUT_QUEUE
(C# version I would think the paren's () would be the only diff, can't
make it fly though...)

//Implement fax event status handers...
objcsFax.objFaxServer.OnOutgoingJobAdded +=new
IFaxServerNotify_OnOutgoingJobAddedEventHandler(objFaxServer_OnOutgoingJobAdded);

objcsFax.objFaxServer.OnOutgoingJobChanged +=new
IFaxServerNotify_OnOutgoingJobChangedEventHandler(objFaxServer_OnOutgoingJobChanged);

objcsFax.objFaxServer.OnServerShutDown +=new
IFaxServerNotify_OnServerShutDownEventHandler(objFaxServer_OnServerShutDown);

objcsFax.objFaxServer.OnOutgoingJobRemoved +=new
IFaxServerNotify_OnOutgoingJobRemovedEventHandler(objFaxServer_OnOutgoingJobRemoved);

ArrayList Values = new ArrayList();

string [] Files = Directory.GetFiles("C:\\FaxDrop\\","*");//give me
everything in this directory...

for(int i=0;i<Files.Length;i++)

{

FileName = Files;

Values.Add(i);


//Set the fax body
objcsFax.objFaxDocument.Body = FileName;;

//Name the document
objcsFax.objFaxDocument.DocumentName = "C#.NET Fax widget";

//Set the fax priority
objcsFax.objFaxDocument.Priority =
FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;

//Add the recipient with the fax number 12225550100
objcsFax.objFaxDocument.Recipients.Add("999-9999","Joe Dirt");

//Choose to attach the fax to the fax receipt
objcsFax.objFaxDocument.AttachFaxToReceipt = true;

//Set the cover page type and the path to the cover page
objcsFax.objFaxDocument.CoverPageType =
FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;

objcsFax.objFaxDocument.CoverPage = "generic";


//Provide the cover page note
objcsFax.objFaxDocument.Note = "Test C# Fax Server";

//Specify that the fax is to be sent at a particular time
objcsFax.objFaxDocument.ScheduleTime = DateTime.Now;

objcsFax.objFaxDocument.Subject = "Today's fax";

//Set the sender properties.
objcsFax.objFaxDocument.Sender.Name = "cs Fax Server";
objcsFax.objFaxDocument.Sender.City = "Cucamonga";
objcsFax.objFaxDocument.Sender.State = "California";
objcsFax.objFaxDocument.Sender.Company = "Bugs Bunny";
objcsFax.objFaxDocument.Sender.Country = "USA";
objcsFax.objFaxDocument.Sender.Email = (e-mail address removed);
objcsFax.objFaxDocument.Sender.FaxNumber = "999-9999";
objcsFax.objFaxDocument.Sender.OfficeLocation = "CA";
objcsFax.objFaxDocument.Sender.OfficePhone = "999-9999";
objcsFax.objFaxDocument.Sender.StreetAddress = "1313 Mocking Bird Ln.";
objcsFax.objFaxDocument.Sender.ZipCode = "12345";
objcsFax.objFaxDocument.Sender.Department = "BB - Fax";

//Save sender information as default
objcsFax.objFaxDocument.Sender.SaveDefaultSender();

//Submit the document to the connected fax server.
objcsFax.JobID =
objcsFax.objFaxDocument.ConnectedSubmit(objcsFax.objFaxServer);

}//end for

}

catch (Exception ex)
{
throw (ex);
}
}

private static void objFaxServer_OnOutgoingJobAdded(FaxServer pFaxServer,
string bstrJobId)
{
MessageBox.Show("JobID: " + bstrJobId + "Added to queue");
}

//This event receives the FaxJobStatus object
private static void objFaxServer_OnOutgoingJobChanged(FaxServer
pFaxServer, string bstrJobId, FaxJobStatus pJobStatus)
{
MessageBox.Show(Convert.ToString(pJobStatus.Status));
}

//Should be raised when fax is sent and is currently not...
private static void objFaxServer_OnServerShutDown(FaxServer pFaxServer)
{
MessageBox.Show("Fax Done");
}

private static void objFaxServer_OnOutgoingJobRemoved(FaxServer
pFaxServer, string bstrJobId)
{
MessageBox.Show("Job Removed");
}

}

}
 
Multiple things
(1)
When you are using FaxServer.Connect to connect to remote (other than local)
fax printers remember the following points (copy/pasted from MSDN)
Using the fax extended COM API you can connect to a remote fax server
running on a Windows® XP or Windows® Server 2003 computer. However, you
cannot connect to a Windows® 2000 fax.

There are some limitations while working with a remote fax connection:

a.. In Windows Server 2003, the fax printer must be shared to support a
remote connection.
b.. You cannot submit faxes remotely to a Windows XP fax.
c.. If you want to submit faxes remotely to a Windows Server 2003 fax you
must have a fax printer connection to that server.
(2)
Why do you say you can register for only one event? Please check the return
value of FaxServer.ListenToServerEvents. When this returns a SUCCESS HRESULT
it means the registration happened fine & there is a problem in the way you
hook the event handlers or some other place.

(3)
The individual events need to be OR-ed and not ADDED. So the correct thing
is
objFaxServer.ListenToServerEvents fsetFXSSVC_ENDED | fsetOUT_QUEUE
& what you have
objFaxServer.ListenToServerEvents fsetFXSSVC_ENDED + fsetOUT_QUEUE
is wrong

(4)
After you send the fax your program needs to wait in order to receive the
events. I don't see any wait in your code. You return right after
ConnectedSubmit call. You can use one of the .NET synchronization constructs
such as ManualResetEvent to wait.

HTH.
--
Raghavendra R
Microsoft Printing, Imaging and Fax Team
This posting is provided "AS IS" with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

PKenney said:
Trouble with C# and FAXCOMEXLib: Fax Service Extended COM API
(faxcomex.dll)

Hello all,

I am having trouble retreiving the Fax Status using C#...

Also I can only seem to set FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM one at
a time...

I can see at run-time that I am Registering the
FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM.fsetFXSSVC_ENDED Event

or which ever SINGLE FAXCOMEXLib.FAX_SERVER_EVENTS_TYPE_ENUM enum I
use...

And my fax works just fine with this code, but does not appear to be
correctly raising the FaxJobStatus events no matter which enum I use...

Am I missing something obvious?
Thanks in advance.

using System;

using System.IO;

using System.ComponentModel;

using System.Collections;

using System.Runtime.InteropServices;

using System.Diagnostics;

using System.Threading;

using FAXCOMEXLib;

namespace csFaxComponent

{

public class csFax

{

protected FAXCOMEXLib.FaxDocument objFaxDocument = new
FAXCOMEXLib.FaxDocumentClass();

protected FAXCOMEXLib.FaxServer objFaxServer;

protected object JobID;

public static void Main()

{

try

{

csFax objcsFax = new csFax();

string FileName;

objcsFax.objFaxServer = new FAXCOMEXLib.FaxServer();

objcsFax.objFaxServer.Connect("AFaxServer");

//Register for server Fax Job Status events, this method has a pointer to
the

//IFaxServerNotify Interface that implements the FaxJobStatus Class, that
enables the

//caller to receive dynamic status messages...

//You do not create the FaxJobStatus class directly it is received as part
of a

//notification when you implement "ListenToServerEvents"

//Having trouble with multicasting this enum, Microsoft has a VB 6 example
that does not appear to convert well to C#

objcsFax.objFaxServer.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYP
E_ENUM.fsetFXSSVC_ENDED);
objcsFax.objFaxServer.ListenToServerEvents(FAXCOMEXLib.FAX_SERVER_EVENTS_TYP
E_ENUM.fsetOUT_QUEUE);

//E.G.: objFaxServer.ListenToServerEvents fsetFXSSVC_ENDED + fsetOUT_QUEUE
(C# version I would think the paren's () would be the only diff, can't
make it fly though...)

//Implement fax event status handers...
objcsFax.objFaxServer.OnOutgoingJobAdded +=new
IFaxServerNotify_OnOutgoingJobAddedEventHandler(objFaxServer_OnOutgoingJobAd
ded);

objcsFax.objFaxServer.OnOutgoingJobChanged +=new
IFaxServerNotify_OnOutgoingJobChangedEventHandler(objFaxServer_OnOutgoingJob
Changed);

objcsFax.objFaxServer.OnServerShutDown +=new
IFaxServerNotify_OnServerShutDownEventHandler(objFaxServer_OnServerShutDown)
;

objcsFax.objFaxServer.OnOutgoingJobRemoved +=new
IFaxServerNotify_OnOutgoingJobRemovedEventHandler(objFaxServer_OnOutgoingJob
Removed);

ArrayList Values = new ArrayList();

string [] Files = Directory.GetFiles("C:\\FaxDrop\\","*");//give me
everything in this directory...

for(int i=0;i<Files.Length;i++)

{

FileName = Files;

Values.Add(i);


//Set the fax body
objcsFax.objFaxDocument.Body = FileName;;

//Name the document
objcsFax.objFaxDocument.DocumentName = "C#.NET Fax widget";

//Set the fax priority
objcsFax.objFaxDocument.Priority =
FAXCOMEXLib.FAX_PRIORITY_TYPE_ENUM.fptHIGH;

//Add the recipient with the fax number 12225550100
objcsFax.objFaxDocument.Recipients.Add("999-9999","Joe Dirt");

//Choose to attach the fax to the fax receipt
objcsFax.objFaxDocument.AttachFaxToReceipt = true;

//Set the cover page type and the path to the cover page
objcsFax.objFaxDocument.CoverPageType =
FAXCOMEXLib.FAX_COVERPAGE_TYPE_ENUM.fcptSERVER;

objcsFax.objFaxDocument.CoverPage = "generic";


//Provide the cover page note
objcsFax.objFaxDocument.Note = "Test C# Fax Server";

//Specify that the fax is to be sent at a particular time
objcsFax.objFaxDocument.ScheduleTime = DateTime.Now;

objcsFax.objFaxDocument.Subject = "Today's fax";

//Set the sender properties.
objcsFax.objFaxDocument.Sender.Name = "cs Fax Server";
objcsFax.objFaxDocument.Sender.City = "Cucamonga";
objcsFax.objFaxDocument.Sender.State = "California";
objcsFax.objFaxDocument.Sender.Company = "Bugs Bunny";
objcsFax.objFaxDocument.Sender.Country = "USA";
objcsFax.objFaxDocument.Sender.Email = (e-mail address removed);
objcsFax.objFaxDocument.Sender.FaxNumber = "999-9999";
objcsFax.objFaxDocument.Sender.OfficeLocation = "CA";
objcsFax.objFaxDocument.Sender.OfficePhone = "999-9999";
objcsFax.objFaxDocument.Sender.StreetAddress = "1313 Mocking Bird Ln.";
objcsFax.objFaxDocument.Sender.ZipCode = "12345";
objcsFax.objFaxDocument.Sender.Department = "BB - Fax";

//Save sender information as default
objcsFax.objFaxDocument.Sender.SaveDefaultSender();

//Submit the document to the connected fax server.
objcsFax.JobID =
objcsFax.objFaxDocument.ConnectedSubmit(objcsFax.objFaxServer);

}//end for

}

catch (Exception ex)
{
throw (ex);
}
}

private static void objFaxServer_OnOutgoingJobAdded(FaxServer pFaxServer,
string bstrJobId)
{
MessageBox.Show("JobID: " + bstrJobId + "Added to queue");
}

//This event receives the FaxJobStatus object
private static void objFaxServer_OnOutgoingJobChanged(FaxServer
pFaxServer, string bstrJobId, FaxJobStatus pJobStatus)
{
MessageBox.Show(Convert.ToString(pJobStatus.Status));
}

//Should be raised when fax is sent and is currently not...
private static void objFaxServer_OnServerShutDown(FaxServer pFaxServer)
{
MessageBox.Show("Fax Done");
}

private static void objFaxServer_OnOutgoingJobRemoved(FaxServer
pFaxServer, string bstrJobId)
{
MessageBox.Show("Job Removed");
}

}

}
 
when using FaxComExLib, my C# web application works great in Vista, but in Windows 2003 I get the following error:

Unable to cast COM object of type 'FAXCOMEXLib.FaxServerClass' to interface type 'FAXCOMEXLib.IFaxServer2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{571CED0F-5609-4F40-9176-547E3A72CA7C}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

in my web application's Bin folder if have Interop.FAXCOMEXLib.dll.

The version of c:\windows\system32\fxscomex.dll is 5.2.3790.3959.

Need you help.

Thx
 
Back
Top