Fax Service的COM之使用 |
缺席
|
pcplayer99
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:146 回覆:790 積分:632 註冊:2003-01-21 發送簡訊給我 |
Win2K 以COM的方式封装了Fax Service. 它的VB的代码大概是这样的: Set FaxServer = CreateObject("FaxServer.FaxServer")
FaxServer.Connect ("Host_Name --that hosts the win-2000 Fax_Service--")
FaxServer.ArchiveOutboundFaxes = 5 'queue, may be as many we want
FaxServer.ArchiveDirectory = "c:\Faxes_Send"
FaxServer.Retries = 5
FaxServer.RetryDelay = 1 Set FaxDocument = FaxServer.CreateDocument(Trim(Text3.Text))
FaxDocument.FaxNumber = Trim(Text1.Text)
FaxDocument.DisplayName = "Your Name goes here"
FaxDocument.FileName = Trim(Text3.Text)
FaxDocument.Tsid = "Your ID"
FaxDocument.Send --------------------------------------- 我用DELPHI7 ,采用Import Type Library 的方式把Fax Server的COM Interface 引入为 FAXCOMLib_TLB 其中有:
IFaxServer = interface(IDispatch)
function CreateDocument(const FileName: WideString): IFaxDoc {OleVariant}; safecall; (这里,DLEPHI自动生成的是OleVariant,我将它改为IFaxDoc,因为MSDN里说这个函数是生成IFaxDoc这个Object) 然后我写了程式: procedure TFMFax.Button1Click(Sender: TObject);
var
AFax:IFaxDoc;
AFaxServer:IFaxServer;
begin
AFaxServer:=CoFaxServer.Create;
try
AFaxServer.Connect(''); //Null=local server
AFax:=AFaxServer.CreateDocument('d:\test\test.rtf');
if AFax<>nil then
begin
AFax.FaxNumber:='2233456'; <-----这里出现AV错误。总之,这里只要操作AFax,就出现AV错误。
AFax.FileName:='D:\test\test.rtf';
AFax.Send;
end;
finally
AFax:=nil;
AFaxServer.Disconnect;
AFaxServer:=nil;
end;
end; 不知道这个COM元件该如何使用才对?
|
pcplayer99
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:146 回覆:790 積分:632 註冊:2003-01-21 發送簡訊給我 |
引言: Win2K 以COM的方式封装了Fax Service. 它的VB的代码大概是这样的: Set FaxServer = CreateObject("FaxServer.FaxServer") FaxServer.Connect ("Host_Name --that hosts the win-2000 Fax_Service--") FaxServer.ArchiveOutboundFaxes = 5 'queue, may be as many we want FaxServer.ArchiveDirectory = "c:\Faxes_Send" FaxServer.Retries = 5 FaxServer.RetryDelay = 1 Set FaxDocument = FaxServer.CreateDocument(Trim(Text3.Text)) FaxDocument.FaxNumber = Trim(Text1.Text) FaxDocument.DisplayName = "Your Name goes here" FaxDocument.FileName = Trim(Text3.Text) FaxDocument.Tsid = "Your ID" FaxDocument.Send --------------------------------------- 我用DELPHI7 ,采用Import Type Library 的方式把Fax Server的COM Interface 引入为 FAXCOMLib_TLB 其中有: IFaxServer = interface(IDispatch) function CreateDocument(const FileName: WideString): IFaxDoc {OleVariant}; safecall; (这里,DLEPHI自动生成的是OleVariant,我将它改为IFaxDoc,因为MSDN里说这个函数是生成IFaxDoc这个Object) 然后我写了程式: procedure TFMFax.Button1Click(Sender: TObject); var AFax:IFaxDoc; AFaxServer:IFaxServer; begin AFaxServer:=CoFaxServer.Create; try AFaxServer.Connect(''); //Null=local server AFax:=AFaxServer.CreateDocument('d:\test\test.rtf'); if AFax<>nil then begin AFax.FaxNumber:='2233456'; <-----这里出现AV错误。总之,这里只要操作AFax,就出现AV错误。 AFax.FileName:='D:\test\test.rtf'; AFax.Send; end; finally AFax:=nil; AFaxServer.Disconnect; AFaxServer:=nil; end; end; 不知道这个COM元件该如何使用才对?今天做了一下实验: IFaxServer = interface(IDispatch) function CreateDocument(const FileName: WideString):{ IFaxDoc} OleVariant; safecall; <-------- 这里恢复为原本的OleVariant 然后在程式里: V:=IFaxServer.CreateDocument('d:\test\test.doc'); I:=VarType(V); 查I为$0009,查HELP,这是个varDispatch Reference to an Automation object (an IDispatch interface pointer). OK,按照MSDN的说法,IFaxServer.CreateDocument本来就该得到IFaxDoc 这个Object. 但我怎么才能把一个 varDispatch 类型的OleVariant 变成IFaxDoc呢?该用什么语法? 我试过 MyFax:=V as IFaxDoc; MyFAx:=V; 等,都通不过编译,也就是语法错误。 这里该怎么办? |
pcplayer99
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:146 回覆:790 積分:632 註冊:2003-01-21 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |