How can I delete a CoCreateInstance pointer from my MFC without exit MFC? 
Author Message
 How can I delete a CoCreateInstance pointer from my MFC without exit MFC?

Hi all,

I have a problem to delete a pointer of CoCreateInstace in
my MFC program.

Here's a sample in my MFC program.
OnButtonTest()
{
   *IVIPER *pViper;
   HRESULT hr = ::CoCreateInstance(..., (void **) &pViper);

Quote:
}

In my COM program also has a MDI form view.  My question
is that when I close or exit the COM, I would like to
delete the pointer, so I can recreate the pointer next
time when the user clicks on OnButtonTest() without exit
the MFC.

Thanks,
snx



Sun, 22 Feb 2004 02:27:27 GMT  
 How can I delete a CoCreateInstance pointer from my MFC without exit MFC?
You don't "delete" COM interface pointers, your "release" them. When you are
finished using pViper then release it by calling pViper->Release() and, for
safety, set it to NULL - i.e., pViper = NULL.

Dave Smith


Quote:
> Hi all,

> I have a problem to delete a pointer of CoCreateInstace in
> my MFC program.

> Here's a sample in my MFC program.
> OnButtonTest()
> {
>    *IVIPER *pViper;
>    HRESULT hr = ::CoCreateInstance(..., (void **) &pViper);
> }

> In my COM program also has a MDI form view.  My question
> is that when I close or exit the COM, I would like to
> delete the pointer, so I can recreate the pointer next
> time when the user clicks on OnButtonTest() without exit
> the MFC.

> Thanks,
> snx



Sun, 22 Feb 2004 05:25:43 GMT  
 How can I delete a CoCreateInstance pointer from my MFC without exit MFC?
Thanks Dave,

Ok.  My question is how can I create and delete multiple
objects based on a single CLSID, CoGetClassObject() called
from MFC without close MFC program.

Thanks,
snx

Quote:
>-----Original Message-----
>You don't "delete" COM interface pointers, your "release"
them. When you are
>finished using pViper then release it by calling pViper-
>Release() and, for
>safety, set it to NULL - i.e., pViper = NULL.

>Dave Smith



>> Hi all,

>> I have a problem to delete a pointer of CoCreateInstace
in
>> my MFC program.

>> Here's a sample in my MFC program.
>> OnButtonTest()
>> {
>>    *IVIPER *pViper;
>>    HRESULT hr = ::CoCreateInstance(..., (void **)
&pViper);
>> }

>> In my COM program also has a MDI form view.  My question
>> is that when I close or exit the COM, I would like to
>> delete the pointer, so I can recreate the pointer next
>> time when the user clicks on OnButtonTest() without exit
>> the MFC.

>> Thanks,
>> snx

>.



Sun, 22 Feb 2004 07:29:18 GMT  
 How can I delete a CoCreateInstance pointer from my MFC without exit MFC?
You use the CLSID to tell the COM runtime which object you want to create.
It uses the generic class factory and creates one of these objects for you.
Everytime you call CoCreateInstance, the COM Runtime will create another
unique COM object for you based on the CLSID you ask it to create.

For example.

CComPtr<ISomeComInterface> pPointer;    // pointer to COM object
CComPtr<ISomeComInterface> pPointer2;
pPointer.CoCreateInstance(__uuidof(SomeComInterface));    // ask COM Runtime
to create a object of this type
pPointer2.CoCreateInstance(__uuidof(SomeComInterface));     // ask COM
Runtime to create another one of these objects

pPointer.Release();    // tell COM object you are done with it. If the
reference count is 0, the com object will delete itself
pPointer2.Release();  // again, tell this com object you are done with it
and it will release itself if the reference count is 0

Hope this helps.

Good luck,
Dave White
http://www.slb.com


Quote:
> Thanks Dave,

> Ok.  My question is how can I create and delete multiple
> objects based on a single CLSID, CoGetClassObject() called
> from MFC without close MFC program.

> Thanks,
> snx

> >-----Original Message-----
> >You don't "delete" COM interface pointers, your "release"
> them. When you are
> >finished using pViper then release it by calling pViper-
> >Release() and, for
> >safety, set it to NULL - i.e., pViper = NULL.

> >Dave Smith



> >> Hi all,

> >> I have a problem to delete a pointer of CoCreateInstace
> in
> >> my MFC program.

> >> Here's a sample in my MFC program.
> >> OnButtonTest()
> >> {
> >>    *IVIPER *pViper;
> >>    HRESULT hr = ::CoCreateInstance(..., (void **)
> &pViper);
> >> }

> >> In my COM program also has a MDI form view.  My question
> >> is that when I close or exit the COM, I would like to
> >> delete the pointer, so I can recreate the pointer next
> >> time when the user clicks on OnButtonTest() without exit
> >> the MFC.

> >> Thanks,
> >> snx

> >.



Sun, 22 Feb 2004 09:11:41 GMT  
 How can I delete a CoCreateInstance pointer from my MFC without exit MFC?
I have read your posts several times now, because I think therei ssomething
we are not understanding.

You talk about your COM program and your MFC program. Are these separate
programs?

Also, you are posting to the ATL group. Do you have an ATL COM server which
is being used by an MFC client?

You said that your COM program **ALSO** has a MDI form view. Is your COM
program another standalone executable, i.e., a local, out-of-process COM
server that support its own user interface? If so, is your question about
how to shutdown the COM server from its standalone interface without hurting
your other MFC client program?

Am I even close to your question?

Dave Smith


Quote:
> Thanks Dave,

> Ok.  My question is how can I create and delete multiple
> objects based on a single CLSID, CoGetClassObject() called
> from MFC without close MFC program.

> Thanks,
> snx

> >-----Original Message-----
> >You don't "delete" COM interface pointers, your "release"
> them. When you are
> >finished using pViper then release it by calling pViper-
> >Release() and, for
> >safety, set it to NULL - i.e., pViper = NULL.

> >Dave Smith



> >> Hi all,

> >> I have a problem to delete a pointer of CoCreateInstace
> in
> >> my MFC program.

> >> Here's a sample in my MFC program.
> >> OnButtonTest()
> >> {
> >>    *IVIPER *pViper;
> >>    HRESULT hr = ::CoCreateInstance(..., (void **)
> &pViper);
> >> }

> >> In my COM program also has a MDI form view.  My question
> >> is that when I close or exit the COM, I would like to
> >> delete the pointer, so I can recreate the pointer next
> >> time when the user clicks on OnButtonTest() without exit
> >> the MFC.

> >> Thanks,
> >> snx

> >.



Mon, 23 Feb 2004 04:51:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. how to pass from a program without MFC support to a program using MFC

2. US-TX-DFW DALLAS DEVELOPERS - Visual C++ / MFC / JUST ONE YEAR OF MFC ----MFC---MFC

3. CoCreateInstance() returns CO_E_FIRST w/o MFC?

4. error exiting MFC app

5. Exiting an MFC app

6. MFC dialog based application exit code

7. return a value when an MFC dialog-based app exits

8. Exit the APP with MFC

9. exiting a MFC OCX

10. proper way of releasing all objects and used resources when exiting MFC app

11. mfc CDialog early exit

 

 
Powered by phpBB® Forum Software