According to Supported Win32 APIs for Windows Phone 8, WP8 does support many file manipulation APIs in fileapi.h
like CreateFile2, ReadFile, WriteFile, ...
But when I include <stdio.h>
I can use fopen, fread, fwrite, ...
Using both those APIs, I can create and read/write to a text file.
CreateFile2("hello.txt", ...);
fopen("hello.txt", ...);
... means other parameters, which aren't important to this question.
The other thing is that I don't know where that text file resides. Installed location isn't the case, because it is read-only location. The other case is Local folder, but I don't specify any Local folder path.
So what are the differences between those APIs (in fileapi.h
and stdio.h
) and which location does they act on ?
P/S: I'm doing in the WP Runtime Component
The main difference is the API set these functions use.
<stdio.h>
contains the file APIs of the standard C library, <fileapi.h>
is the Win32 APIs. There are also C++ APIs (<iostream>
) which you could use.
I've found that whatever API you use, you should explicitly set the file location to the Local folder.
Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
Platform::String^ myFileName = Platform::String::Concat(localfolder, "\\myfile.txt");
One thing to watch is that Platform::String^
uses wchar_t
, not char
internally so you need to be a bit careful in specifying the file name.
So, try and find an API that takes wchar_t*
for the file name and use that to avoid having to do character set conversion.
E.g.: Use _wfsopen
instead of fopen
.