using pdk services through c# application

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

using pdk services through c# application

Post by mer »

Hello,

Is there any way the P3D SDK WeatherSystem Services can be used by a C# application

I need such a console application to access this service and print out weather data

https://www.prepar3d.com/SDKv4/sdk/pdk_ ... rvice.html

Thank you
User avatar
Rob McCarthy
Lockheed Martin
Posts: 3703
Joined: Wed Aug 24, 2011 1:37 pm

Re: using pdk services through c# application

Post by Rob McCarthy »

Hello,

You would still need to use C++ to make these calls. You would have to set up your project for C#/C++ interop to make these calls from your managed C# code.

Regards,
Rob McCarthy
Rob McCarthy
Prepar3D® Core Lead
mer
Posts: 25
Joined: Fri Aug 31, 2018 10:52 am

Re: using pdk services through c# application

Post by mer »

Thank you. Could you share an example please?
mer
Posts: 25
Joined: Fri Aug 31, 2018 10:52 am

Re: using pdk services through c# application

Post by mer »

I have unsuccessfully tried to read the global pressure with this code. Could you please point out the issue(s)?

C++
#include "initpdk.h"
#include "PdkPlugin.h"

#include <string>

using namespace P3D;



class SystemReadyCallback : public ICallbackV400
{
public:
SystemReadyCallback() :
m_RefCount(1)
{
}

virtual void Invoke(IParameterListV400* pParams) override;

DEFAULT_REFCOUNT_INLINE_IMPL()
DEFAULT_IUNKNOWN_QI_INLINE_IMPL(ICallbackV400, IID_ICallbackV400)


};

static SystemReadyCallback* s_pSystemReadyCallback = nullptr;

extern "C" __declspec(dllexport) void __stdcall DLLStart(__in __notnull IPdk* pPdk)
{
PdkServices::Init(pPdk);

//s_pSystemReadyCallback = new SystemReadyCallback();

//PdkServices::GetEventService()->RegisterCallback(EVENTID_Message, s_pSystemReadyCallback);

// return getPressure();


}
extern "C" __declspec(dllexport) float getPressure()
{
float pressure = PdkServices::GetWeatherSystem()->GetGlobalBaroPressure();
return pressure;
}

extern "C" __declspec(dllexport) void __stdcall DLLStop(void)
{
if (s_pSystemReadyCallback != nullptr)
{
s_pSystemReadyCallback = nullptr;
}

PdkServices::Shutdown();

}

C#Console Application
#include "initpdk.h"
#include "PdkPlugin.h"

#include <string>

using namespace P3D;



class SystemReadyCallback : public ICallbackV400
{
public:
SystemReadyCallback() :
m_RefCount(1)
{
}

virtual void Invoke(IParameterListV400* pParams) override;

DEFAULT_REFCOUNT_INLINE_IMPL()
DEFAULT_IUNKNOWN_QI_INLINE_IMPL(ICallbackV400, IID_ICallbackV400)


};

static SystemReadyCallback* s_pSystemReadyCallback = nullptr;

extern "C" __declspec(dllexport) void __stdcall DLLStart(__in __notnull IPdk* pPdk)
{
PdkServices::Init(pPdk);

//s_pSystemReadyCallback = new SystemReadyCallback();

//PdkServices::GetEventService()->RegisterCallback(EVENTID_Message, s_pSystemReadyCallback);

// return getPressure();


}
extern "C" __declspec(dllexport) float getPressure()
{
float pressure = PdkServices::GetWeatherSystem()->GetGlobalBaroPressure();
return pressure;
}

extern "C" __declspec(dllexport) void __stdcall DLLStop(void)
{
if (s_pSystemReadyCallback != nullptr)
{
s_pSystemReadyCallback = nullptr;
}

PdkServices::Shutdown();
}
Post Reply