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:
- Change your code so that it uses a
separate file for each calling
process. - Change it so that it uses
semaphores, mutexes or critcial
sections and wait states to control access to the file. - 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
2010-08-18 12:26:12
Quote: "how can manage a file ,which is used only from one process at a time"
Hans Passant
2010-08-18 12:38:21
@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
2010-08-18 12:41:41
@Hans Passant, i am not familiar with English,dont mistake me...
Rajakumar S
2010-08-18 12:46:16
Here's the MSDN page on mutexes: http://msdn.microsoft.com/en-us/library/ms684266%28VS.85%29.aspx
Eric Finn
2010-08-18 12:59:05
@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
2010-08-18 14:07:13
ok i choose mutexs implementation to my code...
Rajakumar S
2010-08-19 03:35:48