?
Solved

Overlapped I/O operation is in progress

Posted on 2011-09-21
1
Medium Priority
?
425 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

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
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

649 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