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
using pdk services through c# application
- Rob McCarthy
- Lockheed Martin
- Posts: 3703
- Joined: Wed Aug 24, 2011 1:37 pm
Re: using pdk services through c# application
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
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
Prepar3D® Core Lead
Re: using pdk services through c# application
Thank you. Could you share an example please?
Re: using pdk services through c# application
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();
}
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();
}