Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 491
  • Last Modified:

Intermittent SHARE.EXE Error with CFILE Open

I'm trying to open a simple text file for writing and I'm running into some intermittent problems. The line of code in question is:

targetfile.Open(LPCTSTR(fname),CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone,&cfe);

Most of the time it works just fine, but every once in a while I get the error:

SHARE.EXE was not loaded, or a shared region was locked

This error seems somewhat bogus since I'm running on Windows XP Pro, and I thought that SHARE.EXE was retired back around Windows 98. To make matters worse, I don't have to do anything (reboot, etc.) to clear the error, I just run the program again and it completes successfully.

Any ideas?
0
surfbored
Asked:
surfbored
  • 4
  • 3
1 Solution
 
bijopuliCommented:
The exact file name u r trying to write? and to which location?

Are u closing the file properly before ur program ends

this is a sharing Violation exception u r getting as u have specified

As u r using WinXP it may be due to another issue. Which Compiler do u use?

Check ur system32 folder contain share.exe (most probably it wont)

Create a notepad file and call it "share.exe" and place it in the system32
folder, it should satisfy the file check. The file is not usually
needed as such but some programs just check to see that the file
exists, the program doesn't care or know that the file is bogus, it
just wants to see that it exists.

This file was used in DOS or Windows
for Workgroups for sharing but the newer versions of Windows don't use
this sharing mechanism although usually the file is in the folder for
the reasons explained.


Regards
Bijo.
0
 
Infinity08Commented:
>> targetfile.Open(LPCTSTR(fname),CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone,&cfe);

Is there another process that has the file open ? Can you open it with read-only access ?
0
 
surfboredAuthor Commented:
bijopuli:
>>The exact file name u r trying to write? and to which location?

The file name changes with user settings, however, I do know that even when the file and path gets hard-coded this error sometimes appears. It's important to remember that most of the time the write works perfectly - only rarely does this error appear and then it goes away with making any changes.

>>Are u closing the file properly before ur program ends

I think so. That is the program is quite complex but this is the only place the file gets written to and it is closed right away. The program does read the same file a lot and shareDenyNone is not necessarily included on these reads. Is it required? Does reading the file lock it? If this is the problem, why doesn't it show up every time?

>>As u r using WinXP it may be due to another issue. Which Compiler do u use?

Compiler is Visual Studio 6.

>>Check ur system32 folder contain share.exe (most probably it wont)

I thought all XP systems included this file? Mine certainly does and I didn't put it there myself. Again, if the absence of this file was the problem then how could it run at all without first putting this file in place? I'll check my users PCs to see if they are missing this file.

Thanks for all your ideas so far. Please let me know if you think of anything else.
0
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.

 
surfboredAuthor Commented:
CORRECTION:

"The file name changes with user settings, however, I do know that even when the file and path gets hard-coded this error sometimes appears. It's important to remember that most of the time the write works perfectly - only rarely does this error appear and then it goes away *WITHOUT* making any changes."
0
 
surfboredAuthor Commented:
Infinity08:

>>Is there another process that has the file open ? Can you open it with read-only access ?

It's possible that another process has this file, I just don't know what it would be (unless it's a system process or anti-virus software?).

The code I give above is the first time this file is created, although it could exist on disk before hand (from a previous run). Other pieces of code further down open it with read-only access, but of course it only gets to those lines of code when the error doesn't occur.

Does that help?

Again, the most troublesome aspect of this error is that it doesn't happen all the time or even with a high frequency. Also, it's "fixed" by simply running the program again. The reading and writing happens pretty fast and the file is very small (~400 bytes), could it just be tripping over itself occasionally due to speed issues?

 
0
 
Infinity08Commented:
>> could it just be tripping over itself occasionally due to speed issues?

That could be the case. You can easily test that out by adding some delays here and there.


>> It's possible that another process has this file, I just don't know what it would be

You can find that out with a file monitor.

Here's a link to FileMon :

http://www.microsoft.com/technet/sysinternals/FileAndDisk/Filemon.mspx

Depending on your OS version, you might need ProcessMon instead :

http://www.microsoft.com/technet/sysinternals/utilities/processmonitor.mspx
0
 
surfboredAuthor Commented:
It turns out there was an error in my status check that would allow one process to open a file before the previous process had closed it.

This is what we had expected all along, although I couldn't find it until Infinity08 recommended the ProcessMonitor software. This revealed the error in all it's shameful glory.

Thank you!

0
 
Infinity08Commented:
Glad you've found the issue !
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now