Androidthings LED blink program with firemonkey


With Android Studio , the following code works with RaspberryPi3.
LED connected to BCM6 blinks correctly.

How to implement this code into C++Builder10.3 Project ?
=========================
#include <android_native_app_glue.h>
#include <pio/peripheral_manager_client.h>
#include <unistd.h> // sleep

void android_main(android_app* app) {
bool led;
APeripheralManagerClient* client = APeripheralManagerClient_new();
AGpio* gpio;
APeripheralManagerClient_openGpio(client, "BCM6", &gpio);
int result = AGpio_setDirection(gpio, AGPIO_DIRECTION_OUT_INITIALLY_LOW);

while (!app->destroyRequested)
{
led = !led;
AGpio_setValue(gpio, led);
sleep(1);
}
AGpio_delete(gpio);
APeripheralManagerClient_delete(client);
}
=========================

I tried the following code with C++Builder10.3 , however could not solve errors.
Is my approach fundamentally wrong ?

//---------------------------------------------------------------------------
#include <fmx.h>
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Memo.hpp>
#include <FMX.ScrollBox.hpp>
#include <FMX.StdCtrls.hpp>
#include <FMX.Types.hpp>

#pragma hdrstop
#include <dlfcn.h>
#include "peripheral_Manager_client.h"
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"

TForm1 *Form1;
void *libhandle;
APeripheralManagerClient* client;
AGpio* gpio;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
Label1->Text=TimeToStr(Now());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
libhandle = dlopen("libandroidthings.so", RTLD_NOW);
*(APeripheralManagerClient**)(APeripheralManagerClient_new)
=(APeripheralManagerClient*)dlsym(libhandle,"APeripheralManagerClient_new");
client = APeripheralManagerClient_new();
APeripheralManagerClient_openGpio(client, "BCM6", &gpio);

*(int**)(AGpio_setDirection)=(int*)dlsym(libhandle,"AGpio_setDirection");
int result = AGpio_setDirection(gpio, AGPIO_DIRECTION_OUT_INITIALLY_LOW);
}