Einzelnen Beitrag anzeigen

Razor
(Gast)

n/a Beiträge
 
#3

Re: Calling an COM object from Delphi

  Alt 6. Okt 2009, 18:00
Ok so is this proper COM i really couldn't find an existing delphi example so i decided to port some c++ code but i guess it didnt go well.I am really tired from all this 5 hours for 1 example i am trying to compile

Delphi-Quellcode:
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleServer, WINSATLib_TLB, StdCtrls,comobj, ComCtrls,activex, ExtCtrls ;

  Type TMyCallback = class (TComObject,IWInSatInitiateEvents)
   function WinSATComplete(hresult: HResult; strDescription: PWideChar): HResult; stdcall;
   function WinSATUpdate(uCurrentTick: longword; uTickTotal: longword; strCurrentState: PWideChar): HResult; stdcall;
   constructor Create;

   end;

var
Form2: TForm2;
i:IWinSATInitiateEvents;
k:_RemotableHandle;
progresposition:integer;
icurrent,itotal:longword;
t:tmycallback;
sa:string;

function TMyCallback.WinSATComplete(hresult: HResult; strDescription: PWideChar): HResult; stdcall;
begin
if Succeeded(hresult) then result:=strtoint(strDescription)
else showmessage(strDescription);
end;

function TMyCallback.WinSATUpdate(uCurrentTick: longword; uTickTotal: longword; strCurrentState: PWideChar): HResult; stdcall;
var
Assesment:^IInitiateWinSATAssessment;
hr:HRESULT;
begin
if uticktotal>0 then begin
  progresposition:=100*ucurrentTick div utickTotal;
  result:=s_ok;
  Assesment:=nil;
  CoInitializeEx(nil, COINIT_APARTMENTTHREADED);
  OleCheck(CoCreateInstance(
      Class_CInitiateWinSAT,
      nil,
      CLSCTX_INPROC_SERVER,
      IInitiateWinSATAssessment,
     Assesment));
  if FAILED(hr) then
   showmessage('Failed to create an instance of IInitiateWinSATAssessment. Failed with ');
end;
end;