Skip to content

C++ Usage

To use the plugin directly from C++ code, add its module to your project's *.Build.cs file.

Add the Module Dependency

Open your project's *.Build.cs file and add "PloxToolsAdMob" to the public dependency modules list:

PublicDependencyModuleNames.AddRange(new string[]
{
    "Core",
    "CoreUObject",
    "Engine",
    "InputCore",
    "EnhancedInput",
    "PloxToolsAdMob"
});

After adding the module, include the plugin header in the C++ class where you want to use AdMob:

#include "AdMobCPPLibrary.h"

The plugin's C++ API is now available in your project. You can open AdMobCPPLibrary.h from your IDE to view all exposed functions and native delegate types.


General Usage Pattern

All plugin functions are exposed as static methods of UAdMobCPPLibrary.

Depending on the operation, a function can be either synchronous or asynchronous.

Synchronous functions return their result immediately or perform an operation without waiting for a native callback. They can be called directly and do not require delegates.

Asynchronous functions return their results through native Unreal delegates. Each asynchronous function accepts its own delegate types in its parameters, depending on the callbacks and data produced by that operation.

The general usage pattern is:

  • Include AdMobCPPLibrary.h.
  • Call the required static function from UAdMobCPPLibrary.
  • For asynchronous functions, create and bind the delegate types required by that function.
  • Pass the bound delegates into the function parameters.
  • Handle the returned result inside the delegate callbacks.

You can view the exact function signatures and required delegate types in AdMobCPPLibrary.h.


Examples

Synchronous Function

Synchronous functions can be called directly and return their result immediately.

The following example checks whether AdMob has been initialized:

#include "AdMobCPPLibrary.h"

bool UMyClass::IsAdMobInitialized()
{
    return UAdMobCPPLibrary::IsAdMobReady();
}

Other synchronous functions may return an enumeration, check whether an ad is ready, or perform an immediate operation without returning a value.

Asynchronous Function

Asynchronous functions require the native delegates declared for that specific operation.

The following example starts the UMP consent flow:

#include "AdMobCPPLibrary.h"

void UMyClass::RequestAdMobConsent()
{
    FOnConsentRequestCompletedNative OnCompleted;
    OnCompleted.BindLambda([](EConsentStatus ConsentStatus)
    {
        UE_LOG(
            LogTemp,
            Log,
            TEXT("Consent request completed. Status: %d"),
            static_cast<int32>(ConsentStatus)
        );
    });

    FOnConsentRequestFailedNative OnFailure;
    OnFailure.BindLambda([](EFormErrorCode ErrorCode, const FString& Message)
    {
        UE_LOG(
            LogTemp,
            Error,
            TEXT("Consent request failed: %s (Code: %d)"),
            *Message,
            static_cast<int32>(ErrorCode)
        );
    });

    UAdMobCPPLibrary::RequestConsent(
        false,
        OnCompleted,
        OnFailure
    );
}

RequestConsent requires FOnConsentRequestCompletedNative and FOnConsentRequestFailedNative. Other asynchronous functions use their own delegate types for callbacks such as loading, displaying, closing, failures, or rewards.


Summary

The plugin exposes its complete C++ interface through UAdMobCPPLibrary.

Synchronous functions are called directly, while asynchronous functions return their results through operation-specific native delegates. The required delegate types and parameter order are defined in AdMobCPPLibrary.h.