Attempt to extract global pressure from weatherSystemService in a COM setting

SDK supports Prepar3D’s philosophy of an open development architecture and encourages third parties to bring new innovations with improved add-ons and training content.
Post Reply
mer
Posts: 25
Joined: Fri Aug 31, 2018 10:52 am

Attempt to extract global pressure from weatherSystemService in a COM setting

Post by mer »

Hello,
I have tried to retrieve the global pressure value from P3d v4 through it's weather service by attempting to access the IWeatherSystemv430 service outside of P3d. Code for my ATL COM server and client below:

Could you please help me out with it?
Thank you

ATL COM server
// HelloWeather.cpp : Implementation of CHelloWeather

#include "stdafx.h"
#include "HelloWeather.h"

#include <Pdk.h>
#include<initpdk.h>
#include<initguid.h>
// CHelloWeather
using namespace P3D;



STDMETHODIMP CHelloWeather::getPressure(IUnknown* ppIdk, float* value)
{
// TODO: Add your implementation code here
PdkServices::Init((P3D::IPdk*)ppIdk);
printf("P3d initialized");
HRESULT hr = E_FAIL;
if (!ppIdk)
{
return hr;
}

/*if (FAILED(static_cast<P3D::IWeatherSystemV430*>(pPdk)->GetGlobalBaroPressure()))
{
goto Error;
}*/
else
{
//return static_cast<P3D::IWeatherSystemV430*>(ppIdk)->GetGlobalBaroPressure();
//*value = static_cast<P3D::IWeatherSystemV430*>(ppIdk)->GetGlobalBaroPressure();
float ReturnValue=static_cast<P3D::IWeatherSystemV430*>(ppIdk)->GetGlobalBaroPressure();
printf("Pressure is ");
}

return hr;
}

ATL COM client
#include<iostream>
#include"D:\Projects\Prepar3D v4 SDK 4.3.29.25520\PDK\COMTest30_091\COMTest30_091\COMTest30_091_i.h"
#include"D:\Projects\Prepar3D v4 SDK 4.3.29.25520\PDK\COMTest30_091\COMTest30_091\COMTest30_091_i.c"

using namespace std;

int main()
{
HRESULT hr;
IHelloWeather *weather = NULL;
hr = CoInitialize(0);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_HelloWeather, NULL,
CLSCTX_INPROC_SERVER,
IID_IHelloWeather, (void**)&weather);

if (SUCCEEDED(hr))
{
IUnknown* ptr = static_cast<IUnknown*>(weather);
FLOAT val;
weather->getPressure(ptr, &val);
cout << "The global pressure is %f" <<val;
weather->Release();
}
else
{
cout << "CoCreateInstance Failed." << endl;
}

}
// Uninitialize COM
CoUninitialize();

return 0;
}
Post Reply