<PRE>
Hi,
ich will von outlook her benachrichtigt werden, wenn neue mails
hereingekommen sind, diese will ich dann auf meinem PDA anzeigen lassen.
ich benutze d5, outlook 2003, aber dank com sollte das ja auf allen outlook-
Versionen funktionieren!
ich hab zuerst eine externe applikation gemacht, welche mittels
...
FOutlook := GetActiveOleObject('Outlook.Application');
FOutlookEvents.Connect(FOutlook);
...
wobei FOutlook ein OLEVariant ist und FOutlookEvents vom typ
TOutlookApplicationEvents ist (von EventSinkImp)
soweit sogut, hat alles geklappt
nun hab ich das ganze genommen und wollte das in ein outlook-addin
reinpacken.
dort würde auch alles funktionieren, wenn dieses
FOutlookEvents.Connect(FOutlook);
nicht immer eine zugriffsverletzung herbeiführen würde!
ich hab jetzt schon solange dran rumgebastelt, dass ich schon am
verzweifeln bin!!! :-(((( *grrrrr*
hier mal der auszug:
-------------------------
unit CoOutlookTestAddIn;
interface
uses SysUtils, ComObj, ActiveX, OutlookTestAddIn_TLB, StdVcl, Outlook_TLB,
AddInDesignerObjects_TLB, Windows, OutlookEvents;
type
TCoOutlookTestAddIn = class(TAutoObject, ICoOutlookTestAddIn, IDTExtensibility2)
protected
{ Protected-Deklarationen }
procedure OnConnection(const Application: IDispatch; ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch; var custom: PSafeArray); safecall;
procedure OnDisconnection(RemoveMode: ext_DisconnectMode; var
custom: PSafeArray); safecall;
procedure OnAddInsUpdate(var custom: PSafeArray); safecall;
procedure OnStartupComplete(var custom: PSafeArray); safecall;
procedure OnBeginShutdown(var custom: PSafeArray); safecall;
private
FOutlookEvents: TOutlookApplicationEvents;
procedure OnNewMail(Sender: TObject);
public
constructor Create;
destructor Destroy; override;
end;
TMyAutoObjectFactory = class(TAutoObjectFactory)
procedure UpdateRegistry(Register: Boolean); override;
end;
implementation
uses ComServ, Dialogs, Registry, Classes;
{ TCoOutlookTestAddIn }
constructor TCoOutlookTestAddIn.Create;
begin
inherited;
FOutlookEvents := TOutlookApplicationEvents.Create(nil);
FOutlookEvents.NewMail := OnNewMail;
end;
destructor TCoOutlookTestAddIn.Destroy;
begin
if Assigned(FOutlookEvents) then
FreeAndNil(FOutlookEvents);
inherited;
end;
procedure TCoOutlookTestAddIn.OnAddInsUpdate(var custom: PSafeArray);
begin
end;
procedure TCoOutlookTestAddIn.OnBeginShutdown(var custom: PSafeArray);
begin
end;
procedure TCoOutlookTestAddIn.OnConnection(const Application: IDispatch;
ConnectMode: ext_ConnectMode; const AddInInst: IDispatch;
var custom: PSafeArray);
begin
ShowMessage('OnConnection');
try
// Das gibt fehler im AddIn, bei App nicht!!
FOutlookEvents.Connect(Application);
{ der einzige unterschied, ist dieses Application: IDispatch,
auch habe ich im AddIn versucht das outlook über GetActiveOleObject
zu holen, aber da heisst es dann nur, "vorgang nicht verfügbar"
auch verschiedenste umwandlungen vom Application objekt hab ich
versucht, alles ohne erfolg :-( }
except
on E: SysUtils.Exception do
ShowMessage('Connect := ' + E.Message);
end;
end;
procedure TCoOutlookTestAddIn.OnDisconnection(
RemoveMode: ext_DisconnectMode; var custom: PSafeArray);
begin
FOutlookEvents.Disconnect;
end;
procedure TCoOutlookTestAddIn.OnNewMail(Sender: TObject);
begin
ShowMessage('New Mail! ');
end;
procedure TCoOutlookTestAddIn.OnStartupComplete(var custom: PSafeArray);
begin
ShowMessage('OnStartupComplete');
end;
{ TMyAutoObjectFactory }
procedure TMyAutoObjectFactory.UpdateRegistry(Register: Boolean);
var
aTReg : TRegistry;
sKey : String;
aSL : TStringList;
i : Integer;
begin
inherited;
sKey := Format('\Software\Microsoft\Office\Outlook\AddIns\ %s', [PROGID]);
if Register then
begin
aTReg := TRegistry.Create;
try
aTReg.OpenKey(sKey, True);
aTReg.WriteString('FriendlyName', 'TCoOutlookTestAddIn');
aTReg.WriteString('Description', 'TCoOutlookTestAddIn');
aTReg.WriteInteger('LoadBehavior', 3);
finally
aTReg.Free;
end;
end
else
begin
aTReg := TRegistry.Create;
try
aSL := TStringList.Create;
try
if aTReg.OpenKey(sKey, False) then
begin
aTReg.GetValueNames(aSL);
for i := 0 to aSL.Count - 1 do
aTReg.DeleteValue(aSL[i]);
aTReg.CloseKey;
aTReg.DeleteKey(sKey);
end;
finally
aSL.Free;
end;
finally
aTReg.Free;
end;
end;
end;
initialization
TMyAutoObjectFactory.Create(ComServer, TCoOutlookTestAddIn, Class_CoOutlookTestAddIn,
ciMultiInstance, tmApartment);
end.
</PRE>
PS: noch ein tipp für den fall das
wenn in einer der folgenden routinen
procedure OnDisconnection
procedure OnAddInsUpdate
procedure OnStartupComplete
procedure OnBeginShutdown
eine unbehandelte exception (ohne eigenen try-except-block) auftritt, dann
setzt outlook das plugin automatisch auf LoadBehavior=2 und euer plugin wird ab sofort nichtmehr geladen ;-)
Hi,
ich will von outlook her benachrichtigt werden, wenn neue mails
hereingekommen sind, diese will ich dann auf meinem PDA anzeigen lassen.
ich benutze d5, outlook 2003, aber dank com sollte das ja auf allen outlook-
Versionen funktionieren!
ich hab zuerst eine externe applikation gemacht, welche mittels
...
FOutlook := GetActiveOleObject('Outlook.Application');
FOutlookEvents.Connect(FOutlook);
...
wobei FOutlook ein OLEVariant ist und FOutlookEvents vom typ
TOutlookApplicationEvents ist (von EventSinkImp)
soweit sogut, hat alles geklappt
nun hab ich das ganze genommen und wollte das in ein outlook-addin
reinpacken.
dort würde auch alles funktionieren, wenn dieses
FOutlookEvents.Connect(FOutlook);
nicht immer eine zugriffsverletzung herbeiführen würde!
ich hab jetzt schon solange dran rumgebastelt, dass ich schon am
verzweifeln bin!!! :-(((( *grrrrr*
hier mal der auszug:
-------------------------
unit CoOutlookTestAddIn;
interface
uses SysUtils, ComObj, ActiveX, OutlookTestAddIn_TLB, StdVcl, Outlook_TLB,
AddInDesignerObjects_TLB, Windows, OutlookEvents;
type
TCoOutlookTestAddIn = class(TAutoObject, ICoOutlookTestAddIn, IDTExtensibility2)
protected
{ Protected-Deklarationen }
procedure OnConnection(const Application: IDispatch; ConnectMode: ext_ConnectMode;
const AddInInst: IDispatch; var custom: PSafeArray); safecall;
procedure OnDisconnection(RemoveMode: ext_DisconnectMode; var
custom: PSafeArray); safecall;
procedure OnAddInsUpdate(var custom: PSafeArray); safecall;
procedure OnStartupComplete(var custom: PSafeArray); safecall;
procedure OnBeginShutdown(var custom: PSafeArray); safecall;
private
FOutlookEvents: TOutlookApplicationEvents;
procedure OnNewMail(Sender: TObject);
public
constructor Create;
destructor Destroy; override;
end;
TMyAutoObjectFactory = class(TAutoObjectFactory)
procedure UpdateRegistry(Register: Boolean); override;
end;
implementation
uses ComServ, Dialogs, Registry, Classes;
{ TCoOutlookTestAddIn }
constructor TCoOutlookTestAddIn.Create;
begin
inherited;
FOutlookEvents := TOutlookApplicationEvents.Create(nil);
FOutlookEvents.NewMail := OnNewMail;
end;
destructor TCoOutlookTestAddIn.Destroy;
begin
if Assigned(FOutlookEvents) then
FreeAndNil(FOutlookEvents);
inherited;
end;
procedure TCoOutlookTestAddIn.OnAddInsUpdate(var custom: PSafeArray);
begin
end;
procedure TCoOutlookTestAddIn.OnBeginShutdown(var custom: PSafeArray);
begin
end;
procedure TCoOutlookTestAddIn.OnConnection(const Application: IDispatch;
ConnectMode: ext_ConnectMode; const AddInInst: IDispatch;
var custom: PSafeArray);
begin
ShowMessage('OnConnection');
try
// Das gibt fehler im AddIn, bei App nicht!!
FOutlookEvents.Connect(Application);
{ der einzige unterschied, ist dieses Application: IDispatch,
auch habe ich im AddIn versucht das outlook über GetActiveOleObject
zu holen, aber da heisst es dann nur, "vorgang nicht verfügbar"
auch verschiedenste umwandlungen vom Application objekt hab ich
versucht, alles ohne erfolg :-( }
except
on E: SysUtils.Exception do
ShowMessage('Connect := ' + E.Message);
end;
end;
procedure TCoOutlookTestAddIn.OnDisconnection(
RemoveMode: ext_DisconnectMode; var custom: PSafeArray);
begin
FOutlookEvents.Disconnect;
end;
procedure TCoOutlookTestAddIn.OnNewMail(Sender: TObject);
begin
ShowMessage('New Mail! ');
end;
procedure TCoOutlookTestAddIn.OnStartupComplete(var custom: PSafeArray);
begin
ShowMessage('OnStartupComplete');
end;
{ TMyAutoObjectFactory }
procedure TMyAutoObjectFactory.UpdateRegistry(Register: Boolean);
var
aTReg : TRegistry;
sKey : String;
aSL : TStringList;
i : Integer;
begin
inherited;
sKey := Format('\Software\Microsoft\Office\Outlook\AddIns\ %s', [PROGID]);
if Register then
begin
aTReg := TRegistry.Create;
try
aTReg.OpenKey(sKey, True);
aTReg.WriteString('FriendlyName', 'TCoOutlookTestAddIn');
aTReg.WriteString('Description', 'TCoOutlookTestAddIn');
aTReg.WriteInteger('LoadBehavior', 3);
finally
aTReg.Free;
end;
end
else
begin
aTReg := TRegistry.Create;
try
aSL := TStringList.Create;
try
if aTReg.OpenKey(sKey, False) then
begin
aTReg.GetValueNames(aSL);
for i := 0 to aSL.Count - 1 do
aTReg.DeleteValue(aSL[i]);
aTReg.CloseKey;
aTReg.DeleteKey(sKey);
end;
finally
aSL.Free;
end;
finally
aTReg.Free;
end;
end;
end;
initialization
TMyAutoObjectFactory.Create(ComServer, TCoOutlookTestAddIn, Class_CoOutlookTestAddIn,
ciMultiInstance, tmApartment);
end.
</PRE>
PS: noch ein tipp für den fall das
wenn in einer der folgenden routinen
procedure OnDisconnection
procedure OnAddInsUpdate
procedure OnStartupComplete
procedure OnBeginShutdown
eine unbehandelte exception (ohne eigenen try-except-block) auftritt, dann
setzt outlook das plugin automatisch auf LoadBehavior=2 und euer plugin wird ab sofort nichtmehr geladen ;-)
Comment