How to use FAXCOMLib in windows service ?

狂风中的少年 提交于 2019-12-07 13:27:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!