Re: MFC and number of times COM intialized

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



It is a single threaded application. To elaborate some more,

void main ( void )
{
func1();
func2();
}

void func1( )
{
CoInitialize(somearguments);
/* Do something here */
CoUninitialize();
}

void func2( )
{
CoInitialize(somearguments);
/* Do something here */
CoUninitialize();
}

As you can see a single threaded application that intializes and
uninitialized COM multiple times. I thought this was illegal. This
is one of the methods. The other method is calling COM intialize and
unitialize routine only once as shown below.

void main ( void )
{
CoInitialize(somearguments);
func1();
func2();
CoUninitialize();
}

void func1( )
{
/* Do something here */
}

void func2( )
{
/* Do something here */
}


Latter method is valid because it was the one I was told is accurate.
But SDK sample states COM can be intialized and unitialized as many
times as desired. Therefore, my conclusion is both methods are
correct.






.



Relevant Pages

  • Prevent linker from unnecessary symbol resolution
    ... void func1() { ... void func2() { ... Srikanth Madani ...
    (comp.lang.c)
  • Re: MFC threads and critical section
    ... An article in SDK states that COM can be intialized in an application ... void main ... As you can see a single threaded application that intializes and ... Threads which don't run message loops but do initialize COM can hang the ...
    (microsoft.public.vc.mfc)
  • Re: MFC threads and critical section
    ... An article in SDK states that COM can be intialized in an application ... void main ... As you can see a single threaded application that intializes and ... unitialize routine only once as shown below. ...
    (microsoft.public.vc.mfc)