locked
Some general questions

    Question

  • Hi,

    I have several questions about metro style development in C++:

    1) Is is possible to use c++/cx from a static library (Metro style app) ? Because even when I set  "Consume Windows Runtime Extension" (/ZW) to Yes
    the following code is not recognized :

    using namespace Platform;
    using namespace Windows::Storage;


    2) What would be the corresponding c++/cx code for this c# code ?

    ApplicationData.Current.LocalSettings.Values["username"] = "alex";

    I mean do we have to write this code in 3 steps in c++ ? First test if key exists and if it exists remove it and finally insert it 
    I would be tempted to write it like that :

    ApplicationData^ appData =  ApplicationData::Current;
    	if (appData->LocalSettings->Values->HasKey("username"))
    		appData->LocalSettings->Values->Remove("username");
    
    	appData->LocalSettings->Values->Insert("username", "alex"); 

    Don't' tell me there is not a simpler option ...


    Saturday, June 16, 2012 9:20 AM

Answers

  • You wrote:

    > 1) Is is possible to use c++/cx from a static library (Metro style app) ? Because even when I set  "Consume Windows Runtime Extension" (/ZW) to Yes
    > the following code is not recognized :

    I don't see that. After setting /ZW in a Blank Static Library (Metro style) I can add using namespace Platform; and get a compile. However, this does generate a LNK4264 warning. This is all documented at http://msdn.microsoft.com/en-us/library/windows/apps/hh771041(v=vs.110).aspx. If you're just consuming WinRT in the static lib, you should be ok, but you don't want to create public ref classes in the static lib -- that needs to be done in a Dll (winrt component project).

    • Marked as answer by Jesse Jiang Wednesday, June 27, 2012 9:42 AM
    Wednesday, June 20, 2012 12:17 AM
    Moderator
  • What's the specific project type here? WRL is C++ (not C++/CX) so it looks like you are mixing C++ WRL code with C++/CX syntax in non-/ZW compiled code
    • Marked as answer by Jesse Jiang Wednesday, June 27, 2012 9:42 AM
    Wednesday, June 20, 2012 12:21 AM
    Moderator

All replies

  • I do see that

    "Quickstart: Local application data (Metro style apps using C#/VB/C++ and XAML)" http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh700361.aspx

    shows that the C#

    localSettings.Values["exampleSetting"] = "Hello Windows";

    corresponds to

    auto values = localSettings->Values;
    values->Insert("exampleSetting", dynamic_cast<PropertyValue^>(PropertyValue::CreateString("Hello Windows")));

    in C++/CX.

    • Proposed as answer by Jesse Jiang Monday, June 18, 2012 12:22 PM
    Saturday, June 16, 2012 9:19 PM
  • Ok thanks so now I have more questions ;-)

    1) When using LocalSettings, is it persistent ? If I close my application and restart it will I retrieve my previous settings ?
        Or do I need to save them inside a file ?

    2) I am trying to implement missing registry functions inside a static lib (first implementation is using filesystem and com access) but now when I try to use c++/cx I get the following errors :

    1>c:\users\vincent\documents\visual studio 2012\projects\lib1\lib1\oal.cpp(252): error C3699: '^' : cannot use this indirection on type 'ABI::Windows::Storage::ApplicationDataContainer'

    #include <windows.storage.h>
    #include <wrl/client.h>
    #include <wrl/wrappers/corewrappers.h>

    using namespace Microsoft::WRL;
    using namespace Microsoft::WRL::Wrappers;
    using namespace ABI::Windows::Storage;
    using namespace ABI::Windows::Foundation;

    LSTATUS APIENTRY RegOpenKeyExW( _In_ HKEY hKey, _In_opt_ LPCWSTR lpSubKey, _In_opt_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult ) { LSTATUS ret = ERROR_SUCCESS; if (hKey == NULL) return ERROR_INVALID_HANDLE; if (phkResult == NULL) return ERROR_INVALID_PARAMETER; ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings; ApplicationDataContainer^ localFolder = ApplicationData::Current->LocalFolder; ... }

    Any idea why ?


    Sunday, June 17, 2012 9:35 AM
  •  

    For the first question:

    Yes, You can follow this sample codes to use local settings

    http://code.msdn.microsoft.com/windowsapps/ApplicationData-sample-fb043eb2#content

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, June 18, 2012 12:47 PM
  • You wrote:

    > 1) Is is possible to use c++/cx from a static library (Metro style app) ? Because even when I set  "Consume Windows Runtime Extension" (/ZW) to Yes
    > the following code is not recognized :

    I don't see that. After setting /ZW in a Blank Static Library (Metro style) I can add using namespace Platform; and get a compile. However, this does generate a LNK4264 warning. This is all documented at http://msdn.microsoft.com/en-us/library/windows/apps/hh771041(v=vs.110).aspx. If you're just consuming WinRT in the static lib, you should be ok, but you don't want to create public ref classes in the static lib -- that needs to be done in a Dll (winrt component project).

    • Marked as answer by Jesse Jiang Wednesday, June 27, 2012 9:42 AM
    Wednesday, June 20, 2012 12:17 AM
    Moderator
  • What's the specific project type here? WRL is C++ (not C++/CX) so it looks like you are mixing C++ WRL code with C++/CX syntax in non-/ZW compiled code
    • Marked as answer by Jesse Jiang Wednesday, June 27, 2012 9:42 AM
    Wednesday, June 20, 2012 12:21 AM
    Moderator