Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
New related comments Number of comments in the last 48 hoursPlay WAV files 1 new comments
|
OLE Error: CoInitialize has not been called
44 comments. Current rating: (30 votes). Leave comments and/ or rate it.
In a project that needed to display HTML documents, I decided to use the TWebBrowser control. I had used this handy ActiveX control successfully in other projects before.
This application was an MDI application, written in Delphi 5. As a 'specialty' I had installed a beta version of Internet Explorer on my system. I am not sure which of this is responsible for it, but when I would call the function in my application to display the HTML document, the TWebBrowser element could not be instantiated.
Instead I would receive an error message:
'CoInitialize has not been called'
The surprising thing is that the webbrowser control shows fine in design mode! I checked and TWebBrowser was properly installed. The underlieing DLL was also registered properly. A call of
regsvr32 shdocvw.dll
did not help. Finally I manually called the CoInitialize() function. I had to add OLE2 to the list of used units. A good place to do this is the initialization part as the sample snippet below shows.
Thanks to Martin Vreeken for pointing out the necessary CoUninitialize() call.
Note:
In a multithreaded application, you have to put a call to CoInitialize() at the beginning of your thread's Execute method and a matching CoUnInitialize() at its end.
 | |  | | uses
ActiveX, Windows;
initialization
CoInitialize(nil);
finalization
CoUnInitialize;
end. | |  | |  |
Comments:
| You are on page 1 of 3, other pages: [1] 2 3 | |
|
|
|
Good point!
|
|
|
|
|
Perfect
|
|
|
|
|
Super
|
|
|
|
|
Thanks for advertizing this problem and its solution. I was about to quit an undebugged program (a DLL actualy, involving a TwebBrowser), and planning to forget about it when I thought to have a look on the web ... and found what the problem was.
|
|
|
|
|
Super duper.. It fixed the current problem leading me onto the next DLL-related /%#/!'%#/!' error.
|
|
|
|
|
Thanks you so much ! That resolved my bug ! Thanks again ! You re so Pro :D
|
|
|
|
|
Thank you! This also resolved a problem of a TADOConnection throwing random exceptions when created programmatically in a DLL (Delphi 7).
|
|
|
|
|
i had the same problem with MS Word automation....
I'll try your hint.
thanks a lot
|
|
|
|
|
Life saver, thanks a million.
|
|
|
|
|
Valeu
|
|
|
|
|
Unfrotunately it didn't solve the problem of TSimpleRSS and TIdHTTP being called from a separate thread. I don't know WTF is happending. :( I added CoInitialize all over the place, and the error still appears.
|
|
|
|
|
I used this in my new procedure:
procedure CreateShortcut(const ShortCutName: string; OnDesktop: boolean);
It worked perfectly in the pasts without initializing with CoInitialize but suddenly is dropped that error message so I used your solution:
procedure CreateShortcut(const ShortCutName: string; OnDesktop: boolean); { OnDesktop: 1=Desktop 0=StartMenu }
var
MyObject : IUnknown;
MySLink : IShellLink;
MyPFile : IPersistFile;
Directory : String;
WFileName : WideString;
MyReg : TRegIniFile;
begin
CoInitialize(nil); <-----
//OLD CODE ...
MyObject := CreateComObject(CLSID_ShellLink);
MySLink := MyObject as IShellLink;
MyPFile := MyObject as IPersistFile;
//OLD CODE ...
CoUninitialize; <-----
end;
Gabriel
newfedra at yahoo.com
|
|
|
|
|
I also would like to thank for this tip -> it allowed me to save a lot of time which I would otherwise spend on fighting with thread-createad ADOConnection :)
|
|
|
|
|
Worked great for me when trying to auotmate Excel.
|
|
|
|
|
Great help!
That fixed the winshell.pas unit I found elsewhere, enabling me to read the content of a desktop shortcut.
Thank you so much! Manfred
|
| You are on page 1 of 3, other pages: [1] 2 3 |
|