首页 \ 问答 \ 文件操作API在fileapi.h和stdio.h中的WP8差异?(WP8 differences between file manipulation APIs in fileapi.h and stdio.h?)

文件操作API在fileapi.h和stdio.h中的WP8差异?(WP8 differences between file manipulation APIs in fileapi.h and stdio.h?)

根据Windows Phone 8支持的Win32 API ,WP8支持fileapi.h许多文件操作API,如CreateFile2,ReadFile,WriteFile,...

但是当我包含<stdio.h>我可以使用fopen,fread,fwrite,...

使用这两个API,我可以创建和读/写文本文件。

CreateFile2("hello.txt", ...);
fopen("hello.txt", ...);

...表示对此问题不重要的其他参数

另一件事是我不知道该文本文件所在的位置。 安装位置不是这样,因为它是只读位置。 另一种情况是本地文件夹,但我没有指定任何本地文件夹路径。

那些API(在fileapi.hstdio.h )之间有什么区别?它们在哪个位置上作用?

P / S:我正在使用WP Runtime Component


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


原文:https://stackoverflow.com/questions/17468435
更新时间:2020-11-02 18:11

最满意答案

主要区别在于这些函数使用的API集。

<stdio.h>包含标准C库的文件API, <fileapi.h>是Win32 API。 您还可以使用C ++ API( <iostream> )。

我发现无论你使用什么API,都应该明确地将文件位置设置为Local文件夹。

Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
Platform::String^ myFileName = Platform::String::Concat(localfolder, "\\myfile.txt");

需要注意的一点是, Platform::String^使用wchar_t ,而不是内部的char因此在指定文件名时需要小心。

因此,尝试找到一个将wchar_t*作为文件名的API,并使用它来避免必须进行字符集转换。

例如:使用_wfsopen而不是fopen


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.

2013-07-04

相关文章

更多

最新问答

更多
  • 如何保护Solr只允许SELECT请求给用户并禁止其他任何东西?(How to secure Solr to allow SELECT request to only users and disallow anything else?)
  • XPath表达式无效/错误TFHpple SWIFT 1.2(XPath Expression not working/incorrect TFHpple SWIFT 1.2)
  • css3 3D变换不能平滑地制作动画(css3 3D transform doesn't animate smoothly)
  • 运行时错误'91'和Outlook.Application = <对象变量或没有设置块变量>?(Run-time error '91' & Outlook.Application = Object variable or With block variable not set?)
  • 慢的webservice问题(Slow webservice problem)
  • textview的不正确对齐方式(Improper alignment of a textview)
  • 在第一步“Hello World”中出现Java错误(Cannot run “Hello World” program in Eclipse)
  • 为什么十六进制地址是14个字符?(why the hex address is 14 character?)
  • 如何在Python中的不同类中使用变量?(How to use variable in different classes in Python?)
  • asp:GridView HYPERLINKFIELD - datanavigateurlformatstring中的asp代码(asp:GridView HYPERLINKFIELD - asp code inside datanavigateurlformatstring)
  • 关于adaboost算法(About adaboost algorithm)
  • 在Matlab上内置图像(Built in Images on Matlab)
  • java swing:输入键事件时焦点丢失(java swing: Focus lost on enter key event)
  • C#中的通用约束,T是相同的TSomethingElse,对吧?(Generic constraints in C#, T is the same TSomethingElse, right?)
  • 从mybatis中的光标获取数据(Fetching data from cursor in mybatis)
  • 在运行时从XML构建对象的最佳方法(Best way for building objects out of XMLs at runtime)
  • 在整个窗口中拉伸sf :: Sprite(Stretch sf::Sprite across entire window)
  • Selenium Node API Web驱动程序等待超时处理程序(Selenium Node API web driver wait timeout handler)
  • 函数使用并且是map的一部分(循环依赖?)(Function uses and is part of map (circular dependency?))
  • 是否可以在C ++ 14中使用可选模板参数创建类型元组?(Is possible to make a tuple of types with optional template parameters in C++14?)
  • PHP从窗帘后面打印/ f(PHP prints /f from behind the curtains)
  • JFrame的contentPane的LayoutManager(LayoutManager of JFrame's contentPane)
  • 用于Instagram Feed的图像滚动(Image Roll Overs for Instagram Feed)
  • 如何显示拉伸字体(双倍宽度/高度)?(How to display stretched font (double width/height)?)
  • 文件操作API在fileapi.h和stdio.h中的WP8差异?(WP8 differences between file manipulation APIs in fileapi.h and stdio.h?)
  • 保存失败后Rails没有回滚事务()(Rails not rolling back transaction after failed save())
  • jqgrid中的分页问题与数组数据(Pagination problem in jqgrid with array data)
  • 重定向时,通过其他页面上的URL调用javascript函数(Call javascript function through url on otherpage while Redirecting)
  • 如何使用InvokeCommandAction调用我的方法并传入参数?(How do I go about using InvokeCommandAction to call a method of mine and pass in parameters?)
  • Jquerymobile按钮仅显示页面的第一个外观(Jquerymobile buttons are shown only first apperance of the page)