?
Solved

Overlapped I/O operation is in progress

Posted on 2011-09-21
1
Medium Priority
?
416 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
[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
1 Comment
 
LVL 4

Accepted Solution

by:
rotem156 earned 2000 total points
ID: 36576652
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month10 days, 2 hours left to enroll

762 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