0

So here is my code:

// wrl-consume-component.cpp

// compile with: runtimeobject.lib
#include <Windows.Foundation.h>
#include <wrl\wrappers\corewrappers.h>
#include <wrl\client.h>
#include <stdio.h>
#include <windows.networking.vpn.h>

using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Networking::Vpn;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;

// Prints an error string for the provided source code line and HRESULT
// value and returns the HRESULT value as an int.
int PrintError(unsigned int line, HRESULT hr)
{
    wprintf_s(L"ERROR: Line:%d HRESULT: 0x%X\n", line, hr);
    return hr;
}

int wmain()
{
    // Initialize the Windows Runtime.
    RoInitializeWrapper initialize(RO_INIT_MULTITHREADED);
    if (FAILED(initialize))
    {
        return PrintError(__LINE__, initialize);
    }

    // Get the activation factory for the IUriRuntimeClass interface.
    ComPtr<VpnManagementAgent> uriFactory;
    HRESULT hr = GetActivationFactory(HStringReference(RuntimeClass_Windows_Networking_Vpn_VpnManagementAgent).Get(), &uriFactory);
    if (FAILED(hr))
    {
        return PrintError(__LINE__, hr);
    }

//    VpnManagementAgent vpn;
auto profiles = uriFactory->GetProfilesAsync().get();
wprintf(L"Found %d profiles\n", profiles.Size());
for (auto vp : profiles)
{
    wprintf(L"Found profile %s\n", vp.ProfileName().c_str());
}}
/*
Output:
Domain name: microsoft.com
*/

It's basically copy paste from msdn and the answer to that question.

I'm compiling like this: cl /diagnostics:column wrl-consume-component.cpp /link RuntimeObject.lib windows.networking.lib

Obviously I'm missing something huge here.

The error message is:

wrl-consume-component.cpp(40,27): error C2027: use of undefined type 'ABI::Windows::Networking::Vpn::VpnManagementAgent'
AnArrayOfFunctions
  • 3,452
  • 2
  • 29
  • 66
  • I can reproduce your error, and further narrow down the scope of the error code in `ComPtr uriFactory`, Similar error:[c2027 undefined type - how to resolve?](https://social.msdn.microsoft.com/Forums/vstudio/en-US/d30ca39b-7335-4e48-a19e-ee51ae91b0a3/c2027-undefined-type-how-to-resolve?forum=vcgeneral) – Strive Sun Jul 05 '19 at 10:36
  • @StriveSun-MSFT Have you tried compiling the "fixed" code - because I've tried a lot of variations including removing the `ComPtr` but it is still giving me the same error. – AnArrayOfFunctions Jul 05 '19 at 10:58
  • @StriveSun-MSFT It seems the problem lays in the fact that VpnManagementAgent has only forward declaration. – AnArrayOfFunctions Jul 05 '19 at 11:05
  • I solved the issue - I was including the C headers. I installed the C++ UWP SDK from Visual Studio Installer and then included the file like so `..\cppwinrt\winrt\windows.networking.vpn.h`. – AnArrayOfFunctions Jul 05 '19 at 12:31

0 Answers0