Fail to get file write access

Hello Guys, I try to write something to my add-on package, but I always get
permission denied error. I have no problem to open file with
fopen(“.\\data\\test.txt”, “rb”);. But I can’t get the write permission with
fopen(“.\\data\\test.txt”, “wb”);. I search sdk, it look like I need to use
“\work” to get the write permission, but I also have no luck with
fopen(“\work\data\\test.txt”, “wb”);, strerror() return “permission denied”.
Please let me know if I miss anything, thanks

Hi, Indeed, to access a file, all of your paths must start with “\\work” such

fopen("\\work\\file.txt", "w");

If you need a subfolder, you have to create one using mkdir before everything


mkdir("\\work\\data", -1);
fopen("\\work\\data\\file.txt", "w");

Don’t forget to use "\" as path separator in your path. If you don’t, it
won’t work at all or you might have strange file architecture. Best regards
Maxime / Asobo

How do functions like SimConnect_AICreateEnrouteATCAircraft() access files in
“\\work” when used in a WASM module? Just plain “\\work\\flightplan.pln”
does not seem to work.

Thanks Maxime, but i still have problem to write file. Here is my code:
mkdir(“\\work\\data”, -1); FILE *hFile=fopen(“\\work\\data\\file.txt”,
“wb+”);//strerror(errno) return “Not a tty” message if(hFile) { char
Char[32]=“this is test string”; size_t Len=fwrite(Char, 1, strlen(Char)+1,
hFile); fseek(hFile, 0, SEEK_SET); char Buf[32]=“”; Len=fread(Buf, 1,
strlen(Char)+1, hFile);//I can confirm fread can get the “this is test
string”, no error here fclose(hFile);//no file been saved at my data folder
hFile=NULL; } Although fopen return a valid pointer, but strerror(errno)
display a error message “Not a tty”. fwrite() and fread() are all ok, I can
see fread return the right string, but file.txt did not created at my data
folder. If there are any other function I need to call to create a file at my
folder? Thanks!

Hi, I tested your code and it works well. If fopen, fwrite and fread work that
means your file is created (the errno code is strange, i m going to
investigate but it shouldn t be a problem). Maybe you don t look at the
correct location. Your “work” folder will be created in the same folder as
your dll/pdb/natvis/… files. (not in your PackageSources folder) If I may
make a comment about your code, you should be careful about

strlen(Char) + 1

because you re going to write unwanted data in your file Best regards Maxime /

Hi Maxime, I have find my file, fwrite() create it to
aircraft-wasm-gauge\work\file.txt I’m not sure, is it right? Thanks!

Hi, Sorry for being late. Are you using SampleWasmModule project as a base of
your addon? If so, it explains “mycompany-aircraft-wasm-gauge” in your path.
Otherwise, it s strange.

Best regards

Maxime / Asobo

Hi Maxime, my fs2020 is not install at default folder, it install at
E:\FS2020. I think that cause the problem. Thanks!