[windows] Can't delete a closed file?
Cym13
cpicard at openmailbox.org
Thu May 9 10:09:23 UTC 2019
Hi,
this is likely not related to D itself but hopefully someone can
help me with this since I'm rather new to windows programming, I
mainly work on linux. I'm trying to bundle a DLL in a binary,
write it in a temp folder, use it and remove the dangling file.
So far I have the following file:
import std;
void main(string[] args) {
import core.runtime;
static immutable libcurl = import("libcurl.dll");
import std.file: write;
auto libpath = tempDir.buildPath("libcurl.dll");
libpath.write(libcurl);
auto libcurlMem = rt_loadLibrary(libpath.toStringz);
import std.net.curl;
"https://dlang.org/".byLine.count.writeln;
rt_unloadLibrary(libcurlMem);
remove(libpath);
}
Compiled with: dmd.exe -Jlibdir test.d
It almost work, I can write, load and use the library, but when
it comes to
removing it nothing works.
std.file.FileException at std\file.d(1045):
C:\users\cym13\Temp\libcurl.dll: Access denied.
----------------
0x00402377 in EntryPoint
0x00413BC7 in EntryPoint
0x00413B49 in EntryPoint
0x004139E3 in EntryPoint
0x0040B77F in EntryPoint
0x7B4754C2 in call_process_entry
0x7B477FC6 in ExitProcess
0x7B4754CE in call_process_entry
I tried using an explicit File handle to explicitely close the
file after
writing to it but that doesn't change anything.
I'm pretty sure I'm missing something basic about the way windows
handles
open files but I don't know what, could someone explain why this
doesn't work
the way I expect it to?
More information about the Digitalmars-d-learn
mailing list