We help IT Professionals succeed at work.

'CoInitialize has not been called ' Exception Message

ali_elmahi
ali_elmahi asked
on
I work with C++ Builder 5
I have Problem using AdO Connection in Thread
On i try to open ADOConnection in side my thread i received this exception message
'CoInitialize has not been called'
how can i solved this problem ...
waiting for help
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2012
Commented:
>>how can i solved this problem

Call 'CoInitialize()' when your application starts and 'CoUninitialize()' before it ends, e.g.

int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
{
  CoInitialize();

  // your app code

  CoUninitialize();
}



Commented:
Note that you must call CoInitializeEx() from EVERY THREAD that is going to use COM.

Commented:
By the way, to quote MSDN from the CoInitialize() page:

"New applications should call CoInitializeEx instead of CoInitialize."