如何在Windows服务中使用FAXCOMLib? [英] How to use FAXCOMLib in windows service ?
问题描述
我实现了一个用于发送传真消息的程序.我使用FAXCOMLib,当我在Windows窗体中调用它时它可以工作.现在我想在Windows服务中调用它,这是我的问题.
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.
代码很简单:
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();
两种方式,代码返回一个id,但是在Windows窗体中,将传真添加到Windows服务中的"Windows传真和扫描"中-否.为什么?我应该怎么做才能使其正常工作?
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 ?
我使用Windows7.
I use Windows 7.
推荐答案
根据文档,似乎FAXCOMLIB仅适用于桌面应用程序:
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
仅台式机应用程序描述不佳,因为它暗示了Web应用程序以外的任何内容.我在控制台应用程序中运行了以下代码,它可以正常运行,因此显然可以视为桌面:
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();
这篇关于如何在Windows服务中使用FAXCOMLib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!