Article View: borland.public.cppbuilder.nativeapi
Article #11296Re: include TForm into ShellExtensionDLL
From: Hern�n Tornielli
Date: Wed, 18 Feb 2004 00:20
Date: Wed, 18 Feb 2004 00:20
67 lines
2478 bytes
2478 bytes
"Remy Lebeau (TeamB)" wrote:
>HRESULT TIContextMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
>{
> //...
> TMyForm *form = new TMyForm(NULL);
> try {
> form->ShowModal();
> }
> __finally {
> delete form;
> }
> //...
>}
>
>Alternatively, use an std::auto_ptr instead of a try...finally:
>
>#include <memory>
>
>HRESULT TIContextMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
>{
> //...
> std::auto_ptr<TMyForm> form(new TMyForm(NULL));
> form->ShowModal();
> //...
>}
A context menu handler is an in-process server that runs in the Explorer
address space. So you should catch exceptions and return an HRESULT
value. Otherwise, Explorer may crash if an exception is thrown.
HRESULT TIContextMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
{
//...
TMyForm* form = NULL;
try {
form = new TMyForm(NULL);
form->ShowModal();
}
catch(...) {
delete form;
return E_FAIL;
}
delete form;
//..
return S_OK;
}
or
#include <memory>
HRESULT TIContextMenuImpl::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
{
//...
try {
const std::auto_ptr<TMyForm> form(new TMyForm(NULL));
form->ShowModal();
}
catch(...) {
return E_FAIL;
}
//..
return S_OK;
}
Hernan Tornielli
Technical Details
Message-ID:
<4032af9a$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<402baeac$1@newsgroups.borland.com> <402bcd77$3@newsgroups.borland.com> <402ebc24$1@newsgroups.borland.com> <402ec23f$1@newsgroups.borland.com> <40310c11$1@newsgroups.borland.com> <40314206$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,12d8f10b74656960 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-17 16:32:29 PST From: "Hern�n Tornielli" <hernan@nospam.net> Newsgroups: borland.public.cppbuilder.nativeapi References: <402baeac$1@newsgroups.borland.com> <402bcd77$3@newsgroups.borland.com> <402ebc24$1@newsgroups.borland.com> <402ec23f$1@newsgroups.borland.com> <40310c11$1@newsgroups.borland.com> <40314206$1@newsgroups.borland.com> Subject: Re: include TForm into ShellExtensionDLL Date: Tue, 17 Feb 2004 21:20:47 -0300 Lines: 70 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 200.59.37.181 Message-ID: <4032af9a$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1077063578 200.59.37.181 (17 Feb 2004 16:19:38 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail