views:

53

answers:

1

Hi Everyone , Iam working in c++ .i have an problem while run an application ,which have my dll within it ,My dll code is suitable to application (needed process).i wrote a log file (xml file) throughout application using fopen within all function(dll source) ,here i receive exception like "cannot access the file ,due to using by another process." .please help me ,how can manage a file ,where can use only one process at a time...

+2  A: 

Unless you are using a different file for each process that uses your DLL then the problem is that you have the potential for multiple processes trying to access the same resource.

You should do one of the following:

  1. Change your code so that it uses a
    separate file for each calling
    process.
  2. Change it so that it uses
    semaphores, mutexes or critcial
    sections and wait states to control access to the file.
  3. Or rewrite your DLL so that it runs as a process in its own right and directly controls data passed to it to place into the file.
ChrisBD
Quote: "how can manage a file ,which is used only from one process at a time"
Hans Passant
@ChrisBD ,I think 2 nd point is suitable for me ,if semaphores,mutexes are possible via c,c++ ,give some references ,its appreciated ,another two points will give me some difficulty ..i feel so .thanks for ur valuable info...
Rajakumar S
@Hans Passant, i am not familiar with English,dont mistake me...
Rajakumar S
Here's the MSDN page on mutexes: http://msdn.microsoft.com/en-us/library/ms684266%28VS.85%29.aspx
Eric Finn
@Rajakumar - I think that mutexs are the best route here as they work across processes as well as threads. Thanks for the link Eric.
ChrisBD
ok i choose mutexs implementation to my code...
Rajakumar S