locked
What to do to access Windows::Foundation::Rect

    Question

  • Basic question from an old-timer C#/WPF turned newbie managed C++.

    I created a new C++ / Windows Store / "DLL (Windows Store apps)". I then created a new class. In my new class, I want to access Windows::Foundation::Rect but the compiler does not recognize "Windows".

    On the other hand, if I create a C++ / Windows Store / "Blank App (XAML)", Windows::Foundation::Rect is readily accessible without me having to do any extra work.

    My question: What do I need to do to get my "DLL (Windows Store apps)" to pick up the Windows::Foundation::Rect (and, in general, whatever namespaces that I need)?

    Thanks in advance.

     Here is MyC.h and MyC.cpp.

    #pragma once
    class MyC
    {
    public:
        MyC(void);
        ~MyC(void);
    };
    
    

    #include "pch.h"
    #include "MyC.h"
    
    MyC::MyC(void)
    {
        Windows::Foundation::Rect r;
    }
    
    MyC::~MyC(void)
    {
    }
    

     

     The compiler outputs:

    Error 1 error C2653: 'Windows' : is not a class or namespace name c:\users\tan\documents\visual studio 2012\projects\accessingwinrt\myc.cpp 6 1 AccessingWinRT
    Error 2 error C2065: 'Rect' : undeclared identifier c:\users\tan\documents\visual studio 2012\projects\accessingwinrt\myc.cpp 6 1 AccessingWinRT
    Error 3 error C2146: syntax error : missing ';' before identifier 'r' c:\users\tan\documents\visual studio 2012\projects\accessingwinrt\myc.cpp 6 1 AccessingWinRT
    Error 4 error C2065: 'r' : undeclared identifier c:\users\tan\documents\visual studio 2012\projects\accessingwinrt\myc.cpp 6 1 AccessingWinRT


    PermanentTan

    Friday, July 26, 2013 2:23 PM

Answers

  • After manually comparing the two project files (DLL vs Blank App), it looks like I need to flip the "Consume Windows Runtime extension" flag (/ZW). It seems to do the trick. Is this the correct way?


    PermanentTan

    • Marked as answer by PermanentTan Friday, August 2, 2013 2:48 PM
    Friday, July 26, 2013 2:35 PM
  • Managed C++ is not supported for Windows Store apps.

    --Rob

    • Marked as answer by PermanentTan Monday, July 29, 2013 6:16 PM
    Friday, July 26, 2013 6:40 PM
    Owner

All replies

  • After manually comparing the two project files (DLL vs Blank App), it looks like I need to flip the "Consume Windows Runtime extension" flag (/ZW). It seems to do the trick. Is this the correct way?


    PermanentTan

    • Marked as answer by PermanentTan Friday, August 2, 2013 2:48 PM
    Friday, July 26, 2013 2:35 PM
  • The /ZW option turns out to be bad for me. My C++ DLL is managed - It is already compiled with /clr. The presence of both /clr and /ZW are not allowed by the compiler. So I am back to square one.

    So I essentially want to build a managed C++ DLL where:

    1. My C++ code has access to managed functions like gcnew

    2. My C++ code also has access to Windows::Foundation::*

    Appreciate any help.


    PermanentTan

    Friday, July 26, 2013 6:35 PM
  • Managed C++ is not supported for Windows Store apps.

    --Rob

    • Marked as answer by PermanentTan Monday, July 29, 2013 6:16 PM
    Friday, July 26, 2013 6:40 PM
    Owner