Solved

Overlapped I/O operation is in progress

Posted on 2011-09-21
1
373 Views
Last Modified: 2016-10-03
Hi all, Experts. I need your urgent support. I'm the author of a commercial application to backup Delphi settings. One  (only one) of my (few) customers has reported an Access violation error starting the app. Having added some tracking code to my app and with a patient collaboration of my customer, I've finally spotted the error where I fill a StringList with the special folders detected by this function:
function TfrmMain.GetSpecialFolder(const FolderId: integer): string;
var
  ppidl : PItemIdList;
begin
  If SHGetSpecialFolderLocation(0,FolderId,ppidl) = NOERROR then
    begin
      SetLength(Result,MAX_PATH);
      If SHGetPathFromIDList(ppidl,PChar(Result)) then
        SetLength(Result,StrLen(PChar(Result)))
      else
        Result := '';
    end
  else
    Result := '';
end;

Open in new window


The Windows error is "Overlapped I/O operation is in progress".

The filling operation is done this way: first, I fill several variables with correct values:

FPersonalDocuments := AddBackSlash(GetSpecialFolder(CSIDL_PERSONAL));
and so on...

AddBackSlash function doesn't need explanation, I suppose :-)

Then I add each valkue to SFList:

SFList.Add('PersDoc=' + FPersonalDocuments);
SFList.Add('DeskPath=' + FDesktopPath);
and so on...

This way my customer get Access violation. Then I added a sleep(100) for each SFList.Add:

SFList.Add('PersDoc=' + FPersonalDocuments);
sleep(100);
SFList.Add('DeskPath=' + FDesktopPath);
sleep(100);
and so on...

This time, we have no Access violation at all, but in the log file Overlapped message is still present and in fact all code after the StringList filling is not eexecuted and the program can't proceed....

I strongly hope someone can help mein this issue. I think this is a bad code design to detect and store Special folders but I don't know how to do it better....

Thanks to all. Any help will be appreciated.

Marco
0
Comment
Question by:Marco Gasi
1 Comment
 
LVL 4

Accepted Solution

by:
rotem156 earned 500 total points
Comment Utility
SetLength(Result,StrLen(PChar(Result)))

Unnecessary, when the string is being set there's no need to reset its length.

function TfrmMain.GetSpecialFolder(const FolderId: integer): string;
var
  ppidl : PItemIdList;
  buffer: array [1..MAX_PATH] of char;
begin
  If SHGetSpecialFolderLocation(0,FolderId,ppidl) = NOERROR then
    begin
     // SetLength(Result,MAX_PATH);
      If SHGetPathFromIDList(ppidl,@Buffer) then
        Result := Buffer;
      else
        Result := '';
    end
  else
    Result := '';
end;

Open in new window

0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now