Board index » delphi » Access Violation Exception when accessing Outlooks object model in ExchExt OL97/2000

Access Violation Exception when accessing Outlooks object model in ExchExt OL97/2000

Hello all
Iv been getting this access violation exception after i tried to add a
commnadbar through outlooks object model.
in ol 2000 the exception is not in my exch ext code
i try to add a command bar in the InstallCommands method (after getting an
instance of ol obj model in the install method).
in Ol 97
the exception accrued in my code (installcommands method )when i tried to
get the ActiveExplorer instance. iv read that theres a bug in ol 97\2000
when accessing the object model..but i cant figure out how to work around
it.

Daniel

use the :-)

 

Re:Access Violation Exception when accessing Outlooks object model in ExchExt OL97/2000


1. What is your code?
2. There might not be an explorer at the time InstallCommands() is called. Track
OnObjectChange() (it will fire at least once); by that time Outlook does have an
Explorer.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Quote
"Daniel Shrem" <shr...@zahav.net.il> wrote in message news:3cfb962d$1_1@dnews...
> Hello all
> Iv been getting this access violation exception after i tried to add a
> commnadbar through outlooks object model.
> in ol 2000 the exception is not in my exch ext code
> i try to add a command bar in the InstallCommands method (after getting an
> instance of ol obj model in the install method).
> in Ol 97
> the exception accrued in my code (installcommands method )when i tried to
> get the ActiveExplorer instance. iv read that theres a bug in ol 97\2000
> when accessing the object model..but i cant figure out how to work around
> it.

> Daniel

> use the :-)

Re:Access Violation Exception when accessing Outlooks object model in ExchExt OL97/2000


Dmitry,
i tried to add the tool bar on the OnObjectChange Method but still the same
problem happens
in OL 97 i  do not get the instance of the explorer when i call
ActiveExplorer.
i found this tip u wrote in a news group about 2 years ago and there u
wrote:

procedure TExchangeExtension.OnSelectionChange(lpeecb: IEXCHEXTCALLBACK);
var hwndExchange:HWND;
begin
  if S_OK = lpeecb.GetWindow(hwndExchange) then begin
    file://this will call DoSelectionChange() below from DoCommand()
    file://otherwise Outlook 97 (always) and Outlook 98/2000 (when
    file://querying for ActiveExplorer) will {*word*88}
    PostMessage(hwndExchange,WM_COMMAND,$F449,0);
  end;
end;

does this have to do with y i cant get an instance of an explorer????
thanks again Dmitry
Daniel
p.s heres the code im runnin.

procedure TTeleMessageExchExt.OnObjectChange(lpeecb: IExchExtCallback);
const
    METHOD_NAME = 'TTeleMessageExchExt.OnObjectChange: ';
var
    app,exp,cmdbars,cmdbar: olevariant;
begin
    try
        Log(LOG_ERROR,METHOD_NAME,'');
        //ApplicationWrapper is recieved from the
IOutlookExtCallback.GetObject, install method
        app := ApplicationWrapper.Application;
        Log(LOG_LOG,METHOD_NAME,'1');
        exp := app.ActiveExplorer;
        Log(LOG_LOG,METHOD_NAME,'2');
        if (vartype(exp) = varempty) or (vartype(exp) = varnull) then
            //this is what is printed on ol97
            Log(LOG_LOG,METHOD_NAME,'explorer is nil')
        else begin
            Log(LOG_LOG,METHOD_NAME,'explorer is not nil');
            cmdbars := exp.commandbars;
            Log(LOG_LOG,METHOD_NAME,'3');
            cmdbar := cmdbars.add;
            cmdbar.Position := msoBarTop;
            cmdBar.Name := 'yoyoyo';
            Log(LOG_LOG,METHOD_NAME,'4');
            cmdbar.visible := true;
            Log(LOG_LOG,METHOD_NAME,'5');
        end;
    except
        on E: Exception do
            Log(LOG_ERROR,METHOD_NAME,E.Message);
    end
end;

Quote
"Dmitry Streblechenko" <dmi...@dimastr.com> wrote in message

news:3cfba229$1_2@dnews...
Quote
> 1. What is your code?
> 2. There might not be an explorer at the time InstallCommands() is called.
Track
> OnObjectChange() (it will fire at least once); by that time Outlook does
have an
> Explorer.

> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool

> "Daniel Shrem" <shr...@zahav.net.il> wrote in message

news:3cfb962d$1_1@dnews...
Quote
> > Hello all
> > Iv been getting this access violation exception after i tried to add a
> > commnadbar through outlooks object model.
> > in ol 2000 the exception is not in my exch ext code
> > i try to add a command bar in the InstallCommands method (after getting
an
> > instance of ol obj model in the install method).
> > in Ol 97
> > the exception accrued in my code (installcommands method )when i tried
to
> > get the ActiveExplorer instance. iv read that theres a bug in ol 97\2000
> > when accessing the object model..but i cant figure out how to work
around
> > it.

> > Daniel

> > use the :-)

Re:Access Violation Exception when accessing Outlooks object model in ExchExt OL97/2000


That post had to do with Outlook 97 producing an AV if you called
IExchExtCallback::GetSelectionCount() from OnSelectionChange().
I just looked at my code - accessing ActiveExplorer from OnObjectChange() seems
to work fine. I don't have a copy of Outlook 97 handy, and my code traps all
exceptions, so it might be that it only succeeds after a second or third try.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

Quote
"Daniel Shrem" <shr...@zahav.net.il> wrote in message news:3cfc8c0d$1_1@dnews...
> Dmitry,
> i tried to add the tool bar on the OnObjectChange Method but still the same
> problem happens
> in OL 97 i  do not get the instance of the explorer when i call
> ActiveExplorer.
> i found this tip u wrote in a news group about 2 years ago and there u
> wrote:

> procedure TExchangeExtension.OnSelectionChange(lpeecb: IEXCHEXTCALLBACK);
> var hwndExchange:HWND;
> begin
>   if S_OK = lpeecb.GetWindow(hwndExchange) then begin
>     file://this will call DoSelectionChange() below from DoCommand()
>     file://otherwise Outlook 97 (always) and Outlook 98/2000 (when
>     file://querying for ActiveExplorer) will {*word*88}
>     PostMessage(hwndExchange,WM_COMMAND,$F449,0);
>   end;
> end;

> does this have to do with y i cant get an instance of an explorer????
> thanks again Dmitry
> Daniel
> p.s heres the code im runnin.

> procedure TTeleMessageExchExt.OnObjectChange(lpeecb: IExchExtCallback);
> const
>     METHOD_NAME = 'TTeleMessageExchExt.OnObjectChange: ';
> var
>     app,exp,cmdbars,cmdbar: olevariant;
> begin
>     try
>         Log(LOG_ERROR,METHOD_NAME,'');
>         file://ApplicationWrapper is recieved from the
> IOutlookExtCallback.GetObject, install method
>         app := ApplicationWrapper.Application;
>         Log(LOG_LOG,METHOD_NAME,'1');
>         exp := app.ActiveExplorer;
>         Log(LOG_LOG,METHOD_NAME,'2');
>         if (vartype(exp) = varempty) or (vartype(exp) = varnull) then
>             file://this is what is printed on ol97
>             Log(LOG_LOG,METHOD_NAME,'explorer is nil')
>         else begin
>             Log(LOG_LOG,METHOD_NAME,'explorer is not nil');
>             cmdbars := exp.commandbars;
>             Log(LOG_LOG,METHOD_NAME,'3');
>             cmdbar := cmdbars.add;
>             cmdbar.Position := msoBarTop;
>             cmdBar.Name := 'yoyoyo';
>             Log(LOG_LOG,METHOD_NAME,'4');
>             cmdbar.visible := true;
>             Log(LOG_LOG,METHOD_NAME,'5');
>         end;
>     except
>         on E: Exception do
>             Log(LOG_ERROR,METHOD_NAME,E.Message);
>     end
> end;

> "Dmitry Streblechenko" <dmi...@dimastr.com> wrote in message
> news:3cfba229$1_2@dnews...
> > 1. What is your code?
> > 2. There might not be an explorer at the time InstallCommands() is called.
> Track
> > OnObjectChange() (it will fire at least once); by that time Outlook does
> have an
> > Explorer.

> > Dmitry Streblechenko (MVP)
> > http://www.dimastr.com/
> > OutlookSpy  - Outlook, CDO
> > and MAPI Developer Tool

> > "Daniel Shrem" <shr...@zahav.net.il> wrote in message
> news:3cfb962d$1_1@dnews...
> > > Hello all
> > > Iv been getting this access violation exception after i tried to add a
> > > commnadbar through outlooks object model.
> > > in ol 2000 the exception is not in my exch ext code
> > > i try to add a command bar in the InstallCommands method (after getting
> an
> > > instance of ol obj model in the install method).
> > > in Ol 97
> > > the exception accrued in my code (installcommands method )when i tried
> to
> > > get the ActiveExplorer instance. iv read that theres a bug in ol 97\2000
> > > when accessing the object model..but i cant figure out how to work
> around
> > > it.

> > > Daniel

> > > use the :-)

Other Threads