使用C# 实现直接操作dc 发传真 FaxStartPrintJob does't work
我现在已经能使用
FaxServerClass fsc = new FaxServerClass();
try
{
fsc.Connect("");
FaxDoc doc = (FaxDoc) fsc.CreateDocument(@"c:\Off.bmp");
doc.FaxNumber = "8915";
doc.RecipientName = "tester";
int i = doc.Send();
}
catch
{
MessageBox.Show("fail to commit file!");
}
finally
{
fsc.Disconnect();
}
但是我想在发传真时, 得到fax 得 device context 直接朝 dc drawstring 或 drawImage
我知道基本得思路是要用到 FaxStartPrintJob SDK。 但下面的代码好象不行, 请高手帮看看。
IntPtr hServer = IntPtr.Zero;
FaxPrintInfo printInfo = new FaxPrintInfo();
printInfo.RecipientNumber = "8915";
printInfo.SizeOfStruct = System.Runtime.InteropServices.Marshal.SizeOf(printInfo);
printInfo.Reserved = null;
printInfo.OutputFileName = null;
FaxContextInfo contextInfo = new FaxContextInfo();
contextInfo.SizeOfStruct = System.Runtime.InteropServices.Marshal.SizeOf(contextInfo);
IntPtr jobId = IntPtr.Zero;
FaxDrill.FaxConnectFaxServer(null, ref hServer);
FaxDrill.FaxStartPrintJob(null, ref printInfo, jobId, ref contextInfo);
Graphics g = Graphics.FromHdc(contextInfo.hDC);
g.DrawImage(new Bitmap("c:\\Greenstone.bmp"), 0, 0);
FaxDrill.EndDoc(contextInfo.hDC);
FaxDrill.FaxClose(hServer);
[StructLayout( LayoutKind.Sequential)]
public class FaxPrintInfo
{
public Int32 SizeOfStruct; // structure size, in bytes
public String DocName; // pointer to document name to display
public String RecipientName; // pointer to recipient's name
public String RecipientNumber; // pointer to recipient's fax number
public String SenderName; // pointer to sender's name
public String SenderCompany; // pointer to sender's company
public String SenderDept; // pointer to sender's department
public String SenderBillingCode; // pointer to billing code
public String Reserved; // must be set to NULL
public String DrEmailAddress; // pointer to e-mail address
public String OutputFileName; // reserved; must be NULL
}
[StructLayout( LayoutKind.Sequential)]
public class FaxContextInfo
{
public Int32 SizeOfStruct; // structure size, in bytes
public IntPtr hDC; // handle to a device context
public String ServerName;
}
public class FaxDrill
{
public FaxDrill()
{
}
[DllImport("winfax.dll", EntryPoint = "FaxConnectFaxServer")]
public static extern bool FaxConnectFaxServer(String machineName, ref IntPtr hServer);
[DllImport("winfax.dll", EntryPoint = "FaxClose")]
public static extern bool FaxClose(IntPtr hServer);
[DllImport("winfax.dll", EntryPoint = "FaxStartPrintJob")]
public static extern bool FaxStartPrintJob(String printerName, ref FaxPrintInfo printInfo, IntPtr faxJobID, ref FaxContextInfo faxContextInfo);
[DllImport("gdi32.dll", EntryPoint = "EndDoc")]
public static extern bool EndDoc(IntPtr hdc);
}