如何建立和注册一个OLE对象 |
尚未結案
|
wxss2004
一般會員 發表:14 回覆:4 積分:3 註冊:2004-07-19 發送簡訊給我 |
|
wameng
版主 發表:31 回覆:1336 積分:1188 註冊:2004-09-16 發送簡訊給我 |
|
wxss2004
一般會員 發表:14 回覆:4 積分:3 註冊:2004-07-19 發送簡訊給我 |
我见过了类似的COM程序:
unit MyOleServerImpl; interface uses
ComObj, ActiveX, Server_TLB, StdVcl; type
TMyOleServer = class(TAutoObject, IMyOleServer)
protected
function Get_CurrentDateTime: TDateTime; safecall;
end; implementation uses
ComServ, SysUtils; function TMyOleServer.Get_CurrentDateTime: TDateTime;
begin
Result := Now
end; initialization
TAutoObjectFactory.Create(ComServer, TMyOleServer, Class_MyOleServer, ciMultiInstance);
end. unit ServerForm; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls; type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
Form1: TForm1; implementation uses
ComServ; {$R *.DFM} procedure TForm1.FormCreate(Sender: TObject);
begin
if ComServer.StartMode = smAutomation then
Application.ShowMainForm := False
end; end. unit Server_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.3.0.1.0 $
// File generated on 2004-11-10 10:59:28 from Type Library described below. // ************************************************************************ //
// Type Lib: C:\Documents and Settings\Administrator\桌面\Automation\Server\Server.tlb (1)
// LIBID: {F1B8B9A2-9A88-11D1-96E5-444553540000}
// LCID: 0
// Helpfile:
// DepndLst:
// (1) v1.0 stdole, (C:\WINDOWS\system32\stdole32.tlb)
// (2) v2.0 StdType, (C:\WINDOWS\system32\olepro32.dll)
// (3) v1.0 StdVCL, (C:\WINDOWS\system32\stdvcl32.dll)
// ************************************************************************ //
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked pointers.
{$WARN SYMBOL_PLATFORM OFF}
{$WRITEABLECONST ON} interface uses Windows, ActiveX, Classes, Graphics, StdVCL, Variants;
// *********************************************************************//
// 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
ServerMajorVersion = 1;
ServerMinorVersion = 0; LIBID_Server: TGUID = '{F1B8B9A2-9A88-11D1-96E5-444553540000}'; IID_IMyOleServer: TGUID = '{F1B8B9A3-9A88-11D1-96E5-444553540000}';
CLASS_MyOleServer: TGUID = '{F1B8B9A4-9A88-11D1-96E5-444553540000}';
type // *********************************************************************//
// Forward declaration of types defined in TypeLibrary
// *********************************************************************//
IMyOleServer = interface;
IMyOleServerDisp = dispinterface; // *********************************************************************//
// Declaration of CoClasses defined in Type Library
// (NOTE: Here we map each CoClass to its Default Interface)
// *********************************************************************//
MyOleServer = IMyOleServer; // *********************************************************************//
// Interface: IMyOleServer
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {F1B8B9A3-9A88-11D1-96E5-444553540000}
// *********************************************************************//
IMyOleServer = interface(IDispatch)
['{F1B8B9A3-9A88-11D1-96E5-444553540000}']
function Get_CurrentDateTime: TDateTime; safecall;
property CurrentDateTime: TDateTime read Get_CurrentDateTime;
end; // *********************************************************************//
// DispIntf: IMyOleServerDisp
// Flags: (4432) Hidden Dual OleAutomation Dispatchable
// GUID: {F1B8B9A3-9A88-11D1-96E5-444553540000}
// *********************************************************************//
IMyOleServerDisp = dispinterface
['{F1B8B9A3-9A88-11D1-96E5-444553540000}']
property CurrentDateTime: TDateTime readonly dispid 1;
end; // *********************************************************************//
// The Class CoMyOleServer provides a Create and CreateRemote method to
// create instances of the default interface IMyOleServer exposed by
// the CoClass MyOleServer. The functions are intended to be used by
// clients wishing to automate the CoClass objects exposed by the
// server of this typelibrary.
// *********************************************************************//
CoMyOleServer = class
class function Create: IMyOleServer;
class function CreateRemote(const MachineName: string): IMyOleServer;
end; implementation uses ComObj; class function CoMyOleServer.Create: IMyOleServer;
begin
Result := CreateComObject(CLASS_MyOleServer) as IMyOleServer;
end; class function CoMyOleServer.CreateRemote(const MachineName: string): IMyOleServer;
begin
Result := CreateRemoteComObject(MachineName, CLASS_MyOleServer) as IMyOleServer;
end; end. program Server; uses
Forms,
ServerForm in 'ServerForm.pas' {Form1},
Server_TLB in 'Server_TLB.pas',
MyOleServerImpl in 'MyOleServerImpl.pas' {MyOleServer: CoClass}; {$R *.TLB} {$R *.RES} begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end. 这个server顺利编译,我用regsrv32 注册成功。
但是:!! Server := CreateOLEObject('Server.MyOleServer'); 可以调用成功 TOleContainer组件却无法识别到它。
而在word的插入-->对象--->里也找不到这个对象。 why?请版主指点。
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |