在 WindowsPhone 8.1 Silverlight 上使用 C++ 访问文件

File access with C++ on WindowsPhone 8.1 Silverlight

我的项目曾经是一个 WP8.1 WRT 项目 -> C++ + Xmal,

现在我把它转换成WP8.1 Silverlight项目-C# + Xmal + C++DLL。

因为我必须同时使用Silverlight和C++(openssl)。

这是我在WP8.1 WRT项目中访问文件的方式

对于资产中的文件:

wchar_t pw_filedir[MAX_PATH];

wcscpy_s( pw_filedir, MAX_PATH, Windows::ApplicationModel::Package::Current->InstalledLocation->Path->Data() );
wcscat_s( pw_filedir, MAX_PATH, L"\Assets\FileName" );
// Then I can do file access with C style

对于隔离存储中的文件

wchar_t pw_filedir[MAX_PATH];
wcscpy_s( pw_filedir, MAX_PATH, Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data() );
wcscat_s( pw_filedir, MAX_PATH, L"\FileName" );
// Then I can do file access with C style

现在它们都不再适用于 WP8.1 Silverlight。

你们有没有试过在 WindowsPhone silverlight 上访问文件?

这里我的意思是:

Project - WP8.1 SL (C#)
Dll - WP8.1 SL native Dll (C++)

所以我需要在 WP8.1 SL C# 项目的本机 DLL 中执行 C++ 文件访问..

非常感谢您的回答!

如果您想在 Windows Phone 8.1 上使用 Silverlight,您必须使用命名空间 System.IO.IsolatedStorage 来读取和写入文件。一个小例子:

private static void StoreToISF(String key, String value)
{
    using (var mutex = new Mutex(true, "mutex"))
    {
        if (mutex.WaitOne(250))
        {
            var isf = IsolatedStorageFile.GetUserStoreForApplication();
            if (isf.FileExists(key + ".txt"))
                isf.DeleteFile(key + ".txt");
            var stream = isf.OpenFile(key + ".txt", System.IO.FileMode.Create);
            var bytes = new byte[value.Length * sizeof(char)];
            Buffer.BlockCopy(value.ToCharArray(), 0, bytes, 0, bytes.Length);
            stream.Write(bytes, 0, bytes.Length);
            stream.Close();
        }

        mutex.ReleaseMutex();
    }
}

好的,我解决了

很有趣,

我在assets文件夹下放了一个文件,

假设文件的名称是 Blah.yyy

它在 WP8.1 WRT 项目上运行良好,

但是在WP8.1 SL项目上无法正常运行。

但是在我将它重命名为Blah.png之后,

C 样式文件函数可以检测到它。

所以,我猜文件本身并没有打包到包中。

它有一个包过滤器,我仍然不知道在哪里设置它。 :-P