贴上代码library testP;uses ComServ, testP_TLB in 'testP_TLB.pas', Unit1 in 'Unit1.pas' {testPrint: CoClass};exports DllGetClassObject, DllCanUnloadNow, DllRegisterServer, DllUnregisterServer;{$R *.TLB}{$R *.RES}begin
end.
unit Unit1;{$WARN SYMBOL_PLATFORM OFF}interfaceuses ComObj, ActiveX, testP_TLB, StdVcl,Dialogs,Printers;type TtestPrint = class(TAutoObject, ItestPrint) public procedure TS;
safecall;
{ Protected declarations } end;
implementationuses ComServ;procedure TtestPrint.TS;var t: textfile;begin
AssignFile(t,'c:/ccc.txt');
Rewrite(t);
Writeln(t, 'aaa');
CloseFile(t);
//Printer.begin
Doc;
//Printer.EndDoc;
// ShowMessage('a');end;
initialization TAutoObjectFactory.Create(ComServer, TtestPrint, Class_testPrint, ciMultiInstance, tmApartment);end.
unit testP_TLB;// ************************************************************************ //// WARNING // ------- // The types declared in this file were generated from data read from a // Type Library. If this type library is explicitly or indirectly (via // another type library referring to this type library) re-imported, or the // 'Refresh' command of the Type Library Editor activated while editing the // Type Library, the contents of this file will be regenerated and all // manual modifications will be lost. // ************************************************************************ //// PASTLWTR : $Revision: 1.130 $// File generated on 2009-3-16 18:32:14 from Type Library described below.// ************************************************************************ //// Type Lib: F:/test/ActiveX/testP.tlb (1)// LIBID: {476A5819-D165-42DF-A502-46343BDD934F}// LCID: 0// Helpfile: // DepndLst: // (1) v2.0 stdole, (C:/WINDOWS/system32/STDOLE2.TLB)// (2) v4.0 StdVCL, (C:/WINDOWS/system32/stdvcl40.dll)// ************************************************************************ //{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers. {$WARN SYMBOL_PLATFORM OFF}{$WRITEABLECONST ON}interfaceuses ActiveX, Classes, Graphics, StdVCL, Variants, Windows;
// *********************************************************************//// GUIDS declared in the TypeLibrary. Following prefixes are used: // Type Libraries : LIBID_xxxx // CoClasses : CLASS_xxxx // DISPInterfaces : DIID_xxxx // Non-DISP interfaces: IID_xxxx // *********************************************************************//const // TypeLibrary Major and minor versions testPMajorVersion = 1;
testPMinorVersion = 0;
LIBID_testP: TGUID = '{476A5819-D165-42DF-A502-46343BDD934F}';
IID_ItestPrint: TGUID = '{38C5D2EC-AF08-40DF-9441-1C8C6ABB2428}';
CLASS_testPrint: TGUID = '{06BB8EB2-E5BA-4E41-9AA2-9D0E7C25C678}';type// *********************************************************************//// Forward declaration of types defined in TypeLibrary // *********************************************************************// ItestPrint = interface;
ItestPrintDisp = dispinterface;// *********************************************************************//// Declaration of CoClasses defined in Type Library // (NOTE: Here we map each CoClass to its Default Interface) // *********************************************************************// testPrint = ItestPrint;// *********************************************************************//// Interface: ItestPrint// Flags: (6464) Dual OleAutomation Replaceable Dispatchable// GUID: {38C5D2EC-AF08-40DF-9441-1C8C6ABB2428}// *********************************************************************// ItestPrint = interface(IDispatch) ['{38C5D2EC-AF08-40DF-9441-1C8C6ABB2428}'] procedure TS;
safecall;
end;
// *********************************************************************//// DispIntf: ItestPrintDisp// Flags: (6464) Dual OleAutomation Replaceable Dispatchable// GUID: {38C5D2EC-AF08-40DF-9441-1C8C6ABB2428}// *********************************************************************// ItestPrintDisp = dispinterface ['{38C5D2EC-AF08-40DF-9441-1C8C6ABB2428}'] procedure TS;
dispid 1;
end;
// *********************************************************************//// The Class CotestPrint provides a Create and CreateRemote method to // create instances of the default interface ItestPrint exposed by // the CoClass testPrint. The functions are intended to be used by // clients wishing to automate the CoClass objects exposed by the // server of this typelibrary. // *********************************************************************// CotestPrint = class class function Create: ItestPrint;
class function CreateRemote(const MachineName: string): ItestPrint;
end;
implementationuses ComObj;class function CotestPrint.Create: ItestPrint;begin
Result := CreateComObject(CLASS_testPrint) as ItestPrint;end;
class function CotestPrint.CreateRemote(const MachineName: string): ItestPrint;begin
Result := CreateRemoteComObject(MachineName, CLASS_testPrint) as ItestPrint;end;
end.