问题
I implemented a program for sending fax messages. I use FAXCOMLib and it works when I call it in windows forms. Now I want to call it in windows service, and this is my problem.
The code is simple:
FaxServer faxServer = new FaxServer();
faxServer.Connect(Environment.MachineName);
object obj = faxServer.CreateDocument("D:\\test.bmp");
FaxDoc fd = (FaxDoc)obj;
fd.FaxNumber = "123xxxxx";
fd.RecipientName = "Tester";
fd.DisplayName = "TestFax";
fd.SenderName = "Annadurai";
int i = fd.Send();
lp.Debug("Sent" + i.ToString()); // Log fax id
faxServer.Disconnect();
I both ways, code returns an id, but in windows forms fax is added to "Windows Fax and Scan", in windows service - NOT. Why? What should I do to make it works ?
I use Windows 7.
回答1:
According to the documentation it appears that FAXCOMLIB only works on desktop applications:
Applies to: desktop apps only
http://msdn.microsoft.com/en-us/library/windows/desktop/ms692375(v=vs.85).aspx
Desktop app only is a poor description as it implies anything but Web Apps. I have the following code running in a console app and it works fine so apparently that counts as desktop:
FaxServer server = new FaxServer();
server.Connect("");
FaxDoc document = server.CreateDocument(@"C:\RHDSetup.log");
document.FaxNumber = @"111-111-1111";
long jobId = document.Send();
来源:https://stackoverflow.com/questions/7793507/how-to-use-faxcomlib-in-windows-service