Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Coinitialize Error

Posted on 2006-10-20
4
Medium Priority
?
1,118 Views
Last Modified: 2012-08-14
I have an application that I built using Delphi 2006 VCL and dtSearch COM api.  It has been working as expected until lately when I get the error "CoInitialize has not been called" when ever I use the SelectDirectory function then try to call the dtSearch COM procedures.  The SelectDirectory procedure had not precipitated the error before but now it does ever time.  I understand that the SelectDirectory function uses COM support in it internal call to the ShBrowseForFolder.  What I need is another way to have a dialog box (that does not use COM) that shows the existing directories available or a way to call CoInitiatize that works.  I called the Coinitialize in the startup of the application but I still got the error in the same situtation.
0
Comment
Question by:mcmahling
  • 2
4 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 17773334
can you paste the line of code where you call SelectDirectory? Because over here I can use it without the need for CoInitialize().

btw, my help says this on CoInitialize():

CoInitialize
Initializes the COM library on the current thread and identifies the concurrency model as single-thread apartment (STA). Applications must initialize the COM library before they can call COM library functions other than CoGetMalloc and memory allocation functions.

New applications should call CoInitializeEx instead of CoInitialize.

Did you try using CoInitializeEx() ?
0
 

Author Comment

by:mcmahling
ID: 17773717
TForm1.Button1Click(Sender: TObject);
var
strChosenDirectory: String;
begin
 if SelectDirectory('Select a Directory', 'C:\' , strChosenDirectory) then
 begin
   blContinueLoop := True;
 end;
end;

I tried CoInitializeEX(nil,0) it also did not work.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 17779005
if you make a new empty project with only these lines, do you still need to call CoInitialize()?
0
 
LVL 9

Accepted Solution

by:
alkisg earned 1500 total points
ID: 17788220
function SelectDirectory(const Caption: string; const Root: WideString;
  var Directory: string; Options: TSelectDirExtOpts = [sdNewUI]; Parent: TWinControl = nil):

If sdNewUI is set in the options (the default), SelectDirectory calls
CoInitializeEx(nil, COINIT_APARTMENTTHREADED)
and after the dialog is shown
CoUninitialize

The Delphi code seems OK, there must be something wrong with the dtSearch COM api.

A workaround would be to pass empty options as a parameter, so that sdNewUI is not set:
if SelectDirectory('Select a Directory', 'C:\' , strChosenDirectory, []) then
  ...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question