Search code examples
c++c++17c++-winrt

c++ Incomplete type error when defining AppServiceConnection with WinRT Console App


I am trying to create a AppServiceConnection but when doing so I get a Incomplete Type not allowed

I verified the header file is imported for that class as mention in other stackoverflow questions.

I tried several different attempted to define the AppServieConnection. Am I putting in the wrong place? The only way it worked was putting it above the main method.

Here is my code

#include "pch.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <windows.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <tchar.h>
#include <stdio.h>
#include <ppltasks.h>
#include <appmodel.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <string>
#include <ppltasks.h>
#include <windows.h>
#include <appmodel.h>
#include <malloc.h>
#include <stdio.h>
#include <assert.h>
using namespace winrt;

using namespace concurrency;
using namespace Windows::Foundation;
using namespace std;
using namespace Windows::ApplicationModel::AppService;


AppServiceConnection connection_worked; // defining it here works but cannot call any methods from it
int main()
{
    init_apartment();
    Uri uri(L"http://aka.ms/cppwinrt");
    printf("Hello, %ls!\n", uri.AbsoluteUri().c_str());
}

class NewClass {
    private:
        Windows::ApplicationModel::AppService::AppServiceConnection connection{nullptr};
        Windows::ApplicationModel::AppService::AppServiceConnection connection2;
        Windows::ApplicationModel::AppService::AppServiceConnection connection3 = nullptr;
        AppServiceConnection connection4;
        AppServiceConnection connection5 = nullptr;
        AppServiceConnection connection6 = AppServiceConnection();

        IAsyncAction InitializeAppServiceConnection() {
            



        }

    public:
        NewClass() {

        }

    
    

};


Solution

  • The error is clear, you are missing AppServiceConnection header file.

    Please add the header file #include <winrt/Windows.ApplicationModel.AppService.h>