• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Attempt to extract global pressure from weatherSystemService in a COM setting

Messages
25
Country
india
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
C++:
// 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:
Code:
#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;
}
 
To initialize PdkServices helper you must pass pointer to IPdk interface. The only known way to get it is parameter in DLLStart function of dll add-on that Prepar3D load on startup. Memory that pointer is pointing to are in Prepar3D process address space. Your client application has its own process address space and can't access Prepar3D's. So I can't help with your example above, it will not work in that approach.
 
Back
Top