std.stdio.File is throwing with the message of: "Access Violation"
Ruby The Roobster
michaeleverestc79 at gmail.com
Thu Aug 19 13:47:56 UTC 2021
On Thursday, 19 August 2021 at 03:25:31 UTC, Jesse Phillips wrote:
tell me what went wrong. I am using DMD 2.097.2
>
> This is an error message you'll get from Windows if the file is
> locked (open by another application).
Odd. This works if I use a console application. It also works if
I use C standard library functions. The file is always closed. I
think it's just Win32 being buggy. For example, create a base
Win32 application in D. Then put this in WM_CREATE:
```d
case WM_CREATE: //Executed on creation of the window...
try {
import core.stdc.stdio;
FILE* file;
file = fopen("file","r"); //NOTE: Replace 'file' with any
file on the system...
fclose(file);
}
catch(Throwable e) {
MessageBoxA(null,cast(const(char)*)e.msg,"ERROR",MB_OK |
MB_ICONERROR);
}
```
This works, no Message Box should be displayed(Note: use 2.097.2,
this is the version I am using, and I don't know about if this
same bug happens on earlier versions).
Now do this:
```d
case WM_CREATE:
try {
import std.stdio;
File file = File("file","r"); //NOTE: Again, replace
'file' with any file on the system...
file.close();
}
catch(Throwable e) {
MessageBoxA(null, cast(const(char)*)e.msg, "ERROR", MB_OK |
MB_ICONERROR);
}
```
For me, this code generates the Message Box. Does this happen for
you?
More information about the Digitalmars-d-learn
mailing list