deaddima
На, попробуй...
На, попробуй...
Код:
library Project1;
uses
Windows, Variants;
const
CLSCTX_INPROC_SERVER = 1;
CLSCTX_INPROC_HANDLER = 2;
CLSCTX_LOCAL_SERVER = 4;
CLSCTX_INPROC_SERVER16 = 8;
CLSCTX_REMOTE_SERVER = $10;
CLSCTX_INPROC_HANDLER16 = $20;
CLSCTX_INPROC_SERVERX86 = $40;
CLSCTX_INPROC_HANDLERX86 = $80;
type
PCLSID = PGUID;
TCLSID = TGUID;
PIID = PGUID;
TIID = TGUID;
POleStr = PWideChar;
var
Reserved: array of Variant;
function CLSIDFromProgID(pszProgID: POleStr; out clsid: TCLSID): HResult; stdcall;
external 'ole32.dll' name 'CLSIDFromProgID';
function CoCreateInstance(const clsid: TCLSID; unkOuter: IUnknown;
dwClsContext: Longint; const iid: TIID; out pv): HResult; stdcall;
external 'ole32.dll' name 'CoCreateInstance';
function CreateOleObject(const ClassName: string): IDispatch;
var
ClassID: TCLSID;
begin
if Succeeded(CLSIDFromProgID(PWideChar(WideString(ClassName)), CLassID)) then
CoCreateInstance(ClassID, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, Result);
end;
Function CreateWord: Boolean; stdcall;
var
i: Integer;
begin
Result:=true;
try
i:= Length(Reserved);
SetLength(Reserved, i+1);
Reserved[i]:= CreateOleObject('Word.Application');
except
Result:=false;
end;
end;
procedure FreeWords(); stdcall;
var
i: Integer;
begin
for i:=0 to Length(Reserved)-1 do begin
Reserved[i].Quit;
Reserved[i]:= Unassigned;
end;
SetLength(Reserved, 0);
end;
exports
FreeWords,
CreateWord;
begin
end.