Solved

Overlapped I/O operation is in progress

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 89
FMX enumerated colours 2 99
Strange behavior when a form is closed 6 57
Tembedded WB animatid gifs not animated on some pcs 2 80
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 The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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