'Calling dll function but file cannot be written when application is open
I have a function in a dll that involves reading and writing a file.
I am calling the dll function in a test application but the file could not be written when the application is still open. I always need to close the test application first before the file could be successfully written.
What do I have to do to fix this?
I am calling the function repeatedly in a loop. When there are multiple items needed to to processed using that function, the application crashes. It works fine when only one item is processed. What can I do?
Note: my dll is actually an .exe that I converted to dll.
Solution 1:[1]
My guess would be the file is already open. Is your code doing a file open and then leaving the file open?
Check the code to make sure there is a matching file close for every file open.
Solution 2:[2]
Open the file with the right sharing permissions? What API are you using to open the file?
Solution 3:[3]
I would recommend using a different file name when you call the function from your test code. If possible, modify the dll to accept a filename.
If not, make sure you open the file in shared mode.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jussij |
| Solution 2 | MSN |
| Solution 3 | Steve Rowe |
