Click here to Skip to main content
15,355,050 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In a project derived from the DirectX12 template, I am trying to append text to a log file. If I try this, the error codes tell me I don't have file permission. It works fine with my game brought in from an older version of Visual Studio and DirectX10 (but of course the DirectX didn't work), so it may be an item in the project properties that I need to change.

My question is: in code derived from the DirectX12 App template, what do I need to do to append text to a log file?

I am using Microsoft Visual Studio Community 2019 Version 16.11.9.

What I have tried:

I created a new project, using the template 'DirectX12 App (Universal Windows - C++/CX)'. I added these lines to the start of ParadiseGameMain::CreateRenderers

VisualC++
FILE* log;
errno_t err;
err = fopen_s(&log, "C:\\Users\\msdk\\Documents\\log.txt", "a");

if (log != NULL)
{
    fputs("Start of logging\n", log);
    fclose(log);
}

This should create the file log.txt in my Documents folder, but when the fopen_s function completes, err is set to 13 ('no file permission'), and log is NULL.

This code works with some other templates, so that makes me think the problem is a feature of the 'DirectX12 App (Universal Windows - C++/CX)' template. I just can't figure out where to find what's missing.
Posted
Updated 24-Jun-22 8:21am
v4
Comments
Richard MacCutchan 31-Jan-22 15:47pm
   
Check if you can create or open that file from a command window.
Member 10629356 31-Jan-22 16:13pm
   
Thanks for your quick response. Yes, I can create the file from a command window or by using the file explorer. Also, if I try to read the file using my project code, it says no file if it isn't there, and no file permission if it is, so I know I've got the right folder.
Richard MacCutchan 31-Jan-22 16:19pm
   
Sorry, there is nothing to work on to help you.
Member 10629356 31-Jan-22 17:58pm
   
Thank you.

1 solution

I think I've figured it out. The code example uses UWP, which insists that I should be using Windows::Storage::StorageFile and its methods. If I try to use fopen_s, it marks it as 'no permission', even if I wrap it up in a task.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900