Answered by:
Problem with casting back an array object?

Question
-
Hi,
I want writing some localsettings with an Platform::Array<String^>^ Like:
Platform::Array<String^>^ settings = ref new Platform::Array<String^>(3); settings[0] = "123"; settings[1] = "1234"; settings[2] = "12345"; ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; auto values = localSettings->Values; values->Insert("Settings", settings);
And then i read the localSettings and cast it back to Platform::Array<String^>^ Like:
ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; auto values = localSettings->Values; Platform::Array<String^>^ settings = safe_cast<Platform::Array<String^>^>(localSettings->Values->Lookup("Settings"));
There occours an violation reading exception in the "vccorlib.h" 's inline function
template <typename __TArg> inline __TArg* WriteOnlyArray<__TArg, 1>::AllocateAndCopyElements(const __TArg* __srcArg, unsigned int __countArg) { __TArg* __dest = AllocateAndZeroInitialize(__countArg); for (unsigned int __i = 0; __i < __countArg; ++__i) { __dest[__i] = __srcArg[__i]; } return __dest; }
the __countArg perimeters passed with some garbage data
Any ideas of what's wrong with my code?
Thanks
- Edited by ReiFukai Friday, January 25, 2013 2:46 PM
Friday, January 25, 2013 2:42 PM
Answers
-
Hi,
As far as I know, the ApplicationDataContainer.Values is a map.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacontainer.values.aspx
In C++/CX, we cannot inset a arrary to a map directly. The complier will throw error with these codes.Platform::Collections::Map<String^,Platform::Array<String^>^>^ map =ref new Platform::Collections::Map<String^,Platform::Array<String^>^> (); map->Insert("first",settings); auto arrayvalues=map->Lookup("first");
Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Jesse Jiang Wednesday, January 30, 2013 6:27 AM
- Marked as answer by Jesse Jiang Thursday, January 31, 2013 2:46 AM
Monday, January 28, 2013 6:35 AM
All replies
-
Hi,
As far as I know, the ApplicationDataContainer.Values is a map.
http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdatacontainer.values.aspx
In C++/CX, we cannot inset a arrary to a map directly. The complier will throw error with these codes.Platform::Collections::Map<String^,Platform::Array<String^>^>^ map =ref new Platform::Collections::Map<String^,Platform::Array<String^>^> (); map->Insert("first",settings); auto arrayvalues=map->Lookup("first");
Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Proposed as answer by Jesse Jiang Wednesday, January 30, 2013 6:27 AM
- Marked as answer by Jesse Jiang Thursday, January 31, 2013 2:46 AM
Monday, January 28, 2013 6:35 AM -
Hi,
I marked my reply as answer, if your issue has not been solved please unmark it and update more information about this issue.
Best regards,
JesseJesse Jiang
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.Thursday, January 31, 2013 2:46 AM