Why doesn't this code work correctly? 
Author Message
 Why doesn't this code work correctly?

Sorry, about the previous posting... bad fingers on the keyboard!

Can anyone tell me why the smart pointer object creation is failing in
my ATL ActiveX component for the second (and so on..) creation attempt,
but then not for normal com api's???

Its like something somewhere is not releasing or being set correctly, but
I can't fathom it out...

Cheers
Richard

---start code---

// OL::_ApplicationPtr == smart pointer to outlook application
// created using:
// #import "e:\Program Files\Microsoft Office\Office\mso9.dll" OL
// #import "e:\Program Files\Microsoft Office\Office\msoutl9.olb" OL
//

OL::_ApplicationPtr outlook;
outlook.CreateInstance("Outlook.Application");
outlook.Detach();
// 1st connect, works fine, now disconnected
// lets do it again

OL::_ApplicationPtr outlook2;
outlook2.CreateInstance("Outlook.Application");
// fails - does not work, but at this point
// the following code works fine, and everytime:
// but once the first smart pointer object has been
// created and deleted it will never work again for
// the lifetime of the Internet Explorer that
// created it

CLSID clsid;
IUnknown* punk;
HRESULT hRetVal = CLSIDFromProgID(OLESTR("Outlook.Application"), &clsid);
hRetVal = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
 IID_IUnknown, (LPVOID *) &punk);

IDispatch* pdisp;
hRetVal = punk->QueryInterface(__uuidof(pdisp), (void**)&pdisp);

outlook2 = pdisp;
// outlook2 now points to a valid application without any problem

OL::_ApplicationPtr outlook3;
outlook3.CreateInstance("Outlook.Application");
// still fails

OL::_ApplicationPtr outlook4;
outlook4.CreateInstance("Outlook.Application");
// still fails

---end code---



Mon, 27 Oct 2003 20:58:57 GMT  
 Why doesn't this code work correctly?
Detach() does not release the interface pointer, it detaches the smart
pointer from the ras pointer so the smart pointer is no longer responsible
for managing reference count. You have a reference leak. You probably want

outlook.Release(); // Attention: not outlook->Release();

But that in itself should not cause the problem you describe. How does the
creation fail? What is the HRESULT?
--
With best wishes,
    Igor Tandetnik


Quote:
> Sorry, about the previous posting... bad fingers on the keyboard!

> Can anyone tell me why the smart pointer object creation is failing in
> my ATL ActiveX component for the second (and so on..) creation attempt,
> but then not for normal com api's???

> Its like something somewhere is not releasing or being set correctly, but
> I can't fathom it out...

> Cheers
> Richard

> ---start code---

> // OL::_ApplicationPtr == smart pointer to outlook application
> // created using:
> // #import "e:\Program Files\Microsoft Office\Office\mso9.dll" OL
> // #import "e:\Program Files\Microsoft Office\Office\msoutl9.olb" OL
> //

> OL::_ApplicationPtr outlook;
> outlook.CreateInstance("Outlook.Application");
> outlook.Detach();
> // 1st connect, works fine, now disconnected
> // lets do it again

> OL::_ApplicationPtr outlook2;
> outlook2.CreateInstance("Outlook.Application");
> // fails - does not work, but at this point
> // the following code works fine, and everytime:
> // but once the first smart pointer object has been
> // created and deleted it will never work again for
> // the lifetime of the Internet Explorer that
> // created it

> CLSID clsid;
> IUnknown* punk;
> HRESULT hRetVal = CLSIDFromProgID(OLESTR("Outlook.Application"), &clsid);
> hRetVal = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER,
>  IID_IUnknown, (LPVOID *) &punk);

> IDispatch* pdisp;
> hRetVal = punk->QueryInterface(__uuidof(pdisp), (void**)&pdisp);

> outlook2 = pdisp;
> // outlook2 now points to a valid application without any problem

> OL::_ApplicationPtr outlook3;
> outlook3.CreateInstance("Outlook.Application");
> // still fails

> OL::_ApplicationPtr outlook4;
> outlook4.CreateInstance("Outlook.Application");
> // still fails

> ---end code---



Mon, 27 Oct 2003 23:51:21 GMT  
 Why doesn't this code work correctly?
Hi Igor

Thanks for responding.

Ok, using your outlook.Release() method:

m_pApp.CreateInstance("Outlook.Application");
m_pApp.Release();

m_pApp.CreateInstance("Outlook.Application");
m_pApp.Release();

I get the following return:

_com_ptr_t<_com_IIID<OL::_Application,&_GUID_00063001_0000_0000_c000_0000000
00046> >::CreateInstance returned 0x80010105

and m_pApp = 0x00000000

Does this make any sense to you?
Richard


Quote:
> Detach() does not release the interface pointer, it detaches the smart
> pointer from the ras pointer so the smart pointer is no longer responsible
> for managing reference count. You have a reference leak. You probably want

> outlook.Release(); // Attention: not outlook->Release();

> But that in itself should not cause the problem you describe. How does the
> creation fail? What is the HRESULT?
> --
> With best wishes,
>     Igor Tandetnik



Tue, 28 Oct 2003 00:30:50 GMT  
 Why doesn't this code work correctly?
0x80010105 is RPC_E_SERVERFAULT "The server threw an exception.", which
usually happens when the server crashes. You better ask about it in Outlook
newsgroup (if there's any). Maybe Outlook requires you to call Quit or
something on the first instance before you can instantiate the second one.
Or maybe it cannot handle when you create two instances so fast - like
there's some race condition. In any case, it seems like Outlook's fault and
you'll need a workaround.
--
With best wishes,
    Igor Tandetnik


Quote:
> Hi Igor

> Thanks for responding.

> Ok, using your outlook.Release() method:

> m_pApp.CreateInstance("Outlook.Application");
> m_pApp.Release();

> m_pApp.CreateInstance("Outlook.Application");
> m_pApp.Release();

> I get the following return:

_com_ptr_t<_com_IIID<OL::_Application,&_GUID_00063001_0000_0000_c000_0000000

- Show quoted text -

Quote:
> 00046> >::CreateInstance returned 0x80010105

> and m_pApp = 0x00000000

> Does this make any sense to you?
> Richard



> > Detach() does not release the interface pointer, it detaches the smart
> > pointer from the ras pointer so the smart pointer is no longer
responsible
> > for managing reference count. You have a reference leak. You probably
want

> > outlook.Release(); // Attention: not outlook->Release();

> > But that in itself should not cause the problem you describe. How does
the
> > creation fail? What is the HRESULT?
> > --
> > With best wishes,
> >     Igor Tandetnik



Tue, 28 Oct 2003 00:42:51 GMT  
 Why doesn't this code work correctly?
Thanks Igor.

Believe me I've tried playing around with Quit methods and stuff and gave up
after spending far too many hours looking at it!! :)

But as you can see I found that using straight forward COM API's to get the
IUnknown/dispatch pointer worked around this problem.  I guess I have to ask
you if you think this workaround is safe?
So far its worked 100%

Thanks for your time
Richard


Quote:
> 0x80010105 is RPC_E_SERVERFAULT "The server threw an exception.", which
> usually happens when the server crashes. You better ask about it in
Outlook
> newsgroup (if there's any). Maybe Outlook requires you to call Quit or
> something on the first instance before you can instantiate the second one.
> Or maybe it cannot handle when you create two instances so fast - like
> there's some race condition. In any case, it seems like Outlook's fault
and
> you'll need a workaround.
> --
> With best wishes,
>     Igor Tandetnik



Tue, 28 Oct 2003 00:59:43 GMT  
 Why doesn't this code work correctly?
That's real strange, because _com_ptr_t::CreateInstance calls
CoCreateInstance internally. There are two differences though. First, it
uses CLSCTX_ALL instead of CLSCTX_LOCAL_SERVER, and second, it requests
_Application interface instead of IUnknown. Try putting those changes, one
by one, in your raw API calls and see which of them reproduces the problem.
--
With best wishes,
    Igor Tandetnik


Quote:
> Thanks Igor.

> Believe me I've tried playing around with Quit methods and stuff and gave
up
> after spending far too many hours looking at it!! :)

> But as you can see I found that using straight forward COM API's to get
the
> IUnknown/dispatch pointer worked around this problem.  I guess I have to
ask
> you if you think this workaround is safe?
> So far its worked 100%

> Thanks for your time
> Richard



> > 0x80010105 is RPC_E_SERVERFAULT "The server threw an exception.", which
> > usually happens when the server crashes. You better ask about it in
> Outlook
> > newsgroup (if there's any). Maybe Outlook requires you to call Quit or
> > something on the first instance before you can instantiate the second
one.
> > Or maybe it cannot handle when you create two instances so fast - like
> > there's some race condition. In any case, it seems like Outlook's fault
> and
> > you'll need a workaround.
> > --
> > With best wishes,
> >     Igor Tandetnik



Tue, 28 Oct 2003 01:18:33 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Why this code doesn't work?

2. Why doesn't this C code work?

3. ADO - Why doesn't this code work?

4. why my stream code doesn't work in window enviroment

5. Why does the code doesn't work with big pictures

6. Why doesn't this code (always) work?

7. Safearray: why doesn't this code work????

8. Windowless control (ATL) doesn't work correctly on VC++ dialog resource

9. Don't know why this doesn't work, but

10. Why doesn't this function work?

11. Why doesn't this work!?!??!

12. why doesn't Type.IsSubclassOf work for interfaces

 

 
Powered by phpBB® Forum Software