Quickstart: C++ for Windows

Get started with the PlayFab Client library for C++. Follow steps to install the package and try out example code for a basic task.

This quickstart helps you make your first PlayFab API call in the using the Client library for C++. Before continuing, make sure you have completed Getting started for developers, which ensures you have a PlayFab account and are familiar with the PlayFab Game Manager.

API reference documentation | Library source code

Requirements

Windows C++ project setup

Installation:

  1. Download and install the PlayFab Cross-Platform (CPP) SDK.
  2. Create a new C++ Console project.
  3. Right-click on the project in Solution Explorer, select Manage NuGet packages, and search for "playfab." You should see a small number of matches, and you're looking for com.playfab.xplatcppsdk.vXXX. = Install the json cpp packages.
  4. Verify that your project complies.

Set up your first API call

This guide provides the minimum steps to make your first PlayFab API call, without any GUI or on-screen feedback. Confirmation is performed using a console print statement.

  1. In Visual Studio, open your C++ Console Application.
  2. Open the main cpp document for the project. If you did not rename the project, the file name will be similar to ConsoleApplication1.cpp`.
  3. Replace the contents of the file with the code shown below.
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "playfab/PlayFabError.h"
#include "playfab/PlayFabClientDataModels.h"
#include "playfab/PlayFabClientApi.h"
#include "playfab/PlayFabSettings.h"
#include <windows.h>

using namespace PlayFab;
using namespace ClientModels;

bool finished = false;

void OnLoginSuccess(const LoginResult& result, void* customData)
{
    printf("Congratulations, you made your first successful API call!\n");
    finished = true;
}

void OnLoginFail(const PlayFabError& error, void* customData)
{
    printf("Something went wrong with your first API call.\n");
    printf("Here's some debug information:\n");
    printf(error.GenerateErrorReport().c_str());
    printf("\n");
    finished = true;
}

int main()
{
    PlayFabSettings::staticSettings->titleId = ("144");

    LoginWithCustomIDRequest request;
    request.CreateAccount = true;
    request.CustomId = "GettingStartedGuide";

    PlayFabClientAPI::LoginWithCustomID(request, OnLoginSuccess, OnLoginFail);

    while (PlayFabClientAPI::Update() != 0)
        Sleep(1);

    printf("Press enter to exit\n");
    getchar();
    return 0;
}

Finish and execute

  1. To run the project, select Debug > Start Debugging.

  2. When it loads, the following text is displayed:

    "Congratulations, you made your first successful API call!"

  3. Start making other API calls, and build your title.