oleserver.pp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. {$mode objfpc}
  2. unit OleServer;
  3. interface
  4. uses Windows, Messages, ActiveX, SysUtils, Classes, ComObj;
  5. type
  6. TVariantArray = Array of OleVariant;
  7. TOleServer = class;
  8. TConnectKind = (ckRunningOrNew,
  9. ckNewInstance,
  10. ckRunningInstance,
  11. ckRemote,
  12. ckAttachToInterface);
  13. TServerEventDispatch = class(TObject, IUnknown, IDispatch)
  14. private
  15. FServer : TOleServer;
  16. protected
  17. function QueryInterface(constref IID: TGUID; out Obj): HResult; stdcall;
  18. function _AddRef: Integer; stdcall;
  19. function _Release: Integer; stdcall;
  20. function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
  21. function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
  22. function GetIDsOfNames(const IID: TGUID; Names: Pointer;
  23. NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
  24. function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
  25. Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
  26. property Server: TOleServer read FServer;
  27. function ServerDisconnect :Boolean;
  28. public
  29. constructor Create(aServer: TOleServer);
  30. end;
  31. PServerData = ^TServerData;
  32. TServerData = record
  33. ClassID: TGUID;
  34. IntfIID: TGUID;
  35. EventIID: TGUID;
  36. LicenseKey: Pointer;
  37. Version: Integer;
  38. InstanceCount: Integer;
  39. end;
  40. TOleServer = class(TComponent, IUnknown)
  41. private
  42. FRemoteMachineName: string;
  43. FServerData: PServerData;
  44. FEventDispatch: TServerEventDispatch;
  45. FEventsConnection: DWord;
  46. protected
  47. function QueryInterface(constref IID: TGUID; out Obj): HResult; stdcall; override;
  48. function _AddRef: Integer; stdcall;
  49. function _Release: Integer; stdcall;
  50. procedure Loaded; override;
  51. procedure InitServerData; virtual; abstract;
  52. function GetServer: IUnknown; virtual;
  53. procedure ConnectEvents(const Obj: IUnknown);
  54. procedure DisconnectEvents(const Obj: Iunknown);
  55. procedure InvokeEvent(DispID: TDispID; var Params: TVariantArray); virtual;
  56. function GetConnectKind: TConnectKind;
  57. procedure SetConnectKind(ck: TConnectKind);
  58. function GetAutoConnect: Boolean;
  59. procedure SetAutoConnect(flag: Boolean);
  60. property ServerData: PServerData read FServerData write FServerData;
  61. property EventDispatch: TServerEventDispatch read FEventDispatch write FEventDispatch;
  62. public
  63. constructor Create(AOwner: TComponent); override;
  64. destructor Destroy; override;
  65. procedure Connect; virtual; abstract;
  66. procedure Disconnect; virtual; abstract;
  67. published
  68. property AutoConnect: Boolean read GetAutoConnect write SetAutoConnect;
  69. property ConnectKind: TConnectKind read GetConnectKind write SetConnectKind;
  70. property RemoteMachineName: string read FRemoteMachineName write FRemoteMachineName;
  71. end;
  72. implementation
  73. function TServerEventDispatch.QueryInterface(constref IID: TGUID; out Obj): HResult; stdcall;
  74. begin
  75. end;
  76. function TServerEventDispatch._AddRef: Integer; stdcall;
  77. begin
  78. end;
  79. function TServerEventDispatch._Release: Integer; stdcall;
  80. begin
  81. end;
  82. function TServerEventDispatch.GetTypeInfoCount(out Count: Integer): HResult; stdcall;
  83. begin
  84. end;
  85. function TServerEventDispatch.GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
  86. begin
  87. end;
  88. function TServerEventDispatch.GetIDsOfNames(const IID: TGUID; Names: Pointer;
  89. NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
  90. begin
  91. end;
  92. function TServerEventDispatch.Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
  93. Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
  94. begin
  95. end;
  96. function TServerEventDispatch.ServerDisconnect :Boolean;
  97. begin
  98. end;
  99. constructor TServerEventDispatch.Create(aServer: TOleServer);
  100. begin
  101. end;
  102. function TOleServer.QueryInterface(constref IID: TGUID; out Obj): HResult; stdcall;
  103. begin
  104. end;
  105. function TOleServer._AddRef: Integer; stdcall;
  106. begin
  107. end;
  108. function TOleServer._Release: Integer; stdcall;
  109. begin
  110. end;
  111. procedure TOleServer.Loaded;
  112. begin
  113. end;
  114. function TOleServer.GetServer: IUnknown;
  115. begin
  116. end;
  117. procedure TOleServer.ConnectEvents(const Obj: IUnknown);
  118. begin
  119. ComObj.InterfaceConnect(Obj, FServerData^.EventIID, FEventDispatch, FEventsConnection);
  120. end;
  121. procedure TOleServer.DisconnectEvents(const Obj: Iunknown);
  122. begin
  123. ComObj.InterfaceDisconnect(Obj, FServerData^.EventIID, FEventsConnection);
  124. end;
  125. procedure TOleServer.InvokeEvent(DispID: TDispID; var Params: TVariantArray);
  126. begin
  127. end;
  128. function TOleServer.GetConnectKind: TConnectKind;
  129. begin
  130. end;
  131. procedure TOleServer.SetConnectKind(ck: TConnectKind);
  132. begin
  133. end;
  134. function TOleServer.GetAutoConnect: Boolean;
  135. begin
  136. end;
  137. procedure TOleServer.SetAutoConnect(flag: Boolean);
  138. begin
  139. end;
  140. constructor TOleServer.Create(AOwner: TComponent);
  141. begin
  142. end;
  143. destructor TOleServer.Destroy;
  144. begin
  145. end;
  146. end.