M
mycwcgr_bak
Unregistered / Unconfirmed
GUEST, unregistred user!
有两段程序,为什么第一段为什么要初始化,而第二段不需要吗?
===============
try
oleinitialize(nil);
anobj:=createcomobject(clsid_shelllink);
shellink:=anobj as ishelllink;
.
.
finally
oleuninitialize;
end;
=======================
unit Project1_TLB;
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
// *********************************************************************//
// 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
Project1MajorVersion = 1;
Project1MinorVersion = 0;
LIBID_Project1: TGUID = '{2CFD7FCA-6E13-457E-B3BF-17BB90B41E32}';
IID_Icw: TGUID = '{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}';
CLASS_cw: TGUID = '{05143E4C-4498-42EB-A975-139F310F0D14}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
Icw = interface;
IcwDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
cw = Icw;
// *********************************************************************//
// Interface: Icw
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}
// *********************************************************************//
Icw = interface(IDispatch)
['{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}']
procedure my(aa: OleVariant);
safecall;
end;
// *********************************************************************//
// DispIntf: IcwDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}
// *********************************************************************//
IcwDisp = dispinterface
['{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}']
procedure my(aa: OleVariant);
dispid 1;
end;
// *********************************************************************//
// The Class Cocw provides a Create and CreateRemote method to
// create instances of the default interface Icw exposed by
// the CoClass cw. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
Cocw = class
class function Create: Icw;
class function CreateRemote(const MachineName: string): Icw;
end;
implementation
uses ComObj;
class function Cocw.Create: Icw;
begin
Result := CreateComObject(CLASS_cw) as Icw;
end;
class function Cocw.CreateRemote(const MachineName: string): Icw;
begin
Result := CreateRemoteComObject(MachineName, CLASS_cw) as Icw;
end;
end.
===============
try
oleinitialize(nil);
anobj:=createcomobject(clsid_shelllink);
shellink:=anobj as ishelllink;
.
.
finally
oleuninitialize;
end;
=======================
unit Project1_TLB;
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
interface
uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;
// *********************************************************************//
// 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
Project1MajorVersion = 1;
Project1MinorVersion = 0;
LIBID_Project1: TGUID = '{2CFD7FCA-6E13-457E-B3BF-17BB90B41E32}';
IID_Icw: TGUID = '{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}';
CLASS_cw: TGUID = '{05143E4C-4498-42EB-A975-139F310F0D14}';
type
// *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
Icw = interface;
IcwDisp = dispinterface;
// *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
cw = Icw;
// *********************************************************************//
// Interface: Icw
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}
// *********************************************************************//
Icw = interface(IDispatch)
['{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}']
procedure my(aa: OleVariant);
safecall;
end;
// *********************************************************************//
// DispIntf: IcwDisp
// Flags: (4416) Dual OleAutomation Dispatchable
// GUID: {BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}
// *********************************************************************//
IcwDisp = dispinterface
['{BD32CDE8-A713-47E0-AE9B-EEDAEEF8710F}']
procedure my(aa: OleVariant);
dispid 1;
end;
// *********************************************************************//
// The Class Cocw provides a Create and CreateRemote method to
// create instances of the default interface Icw exposed by
// the CoClass cw. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
Cocw = class
class function Create: Icw;
class function CreateRemote(const MachineName: string): Icw;
end;
implementation
uses ComObj;
class function Cocw.Create: Icw;
begin
Result := CreateComObject(CLASS_cw) as Icw;
end;
class function Cocw.CreateRemote(const MachineName: string): Icw;
begin
Result := CreateRemoteComObject(MachineName, CLASS_cw) as Icw;
end;
end.