Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Coinitialize Error

Posted on 2006-10-20
4
Medium Priority
?
1,117 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

670 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