Solved

Overlapped I/O operation is in progress

Posted on 2011-09-21
1
407 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

739 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