We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Intermittent SHARE.EXE Error with CFILE Open

surfbored
surfbored asked
on
Medium Priority
841 Views
Last Modified: 2008-01-09
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?
Comment
Watch Question

bijopuliSoftware Architect

Commented:
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.
CERTIFIED EXPERT
Top Expert 2009

Commented:
>> 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 ?

Author

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.

Author

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."

Author

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?

 
CERTIFIED EXPERT
Top Expert 2009
Commented:
>> 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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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!

CERTIFIED EXPERT
Top Expert 2009

Commented:
Glad you've found the issue !
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.