Hello,
I attempted to make a small weather add-on which would write the variable values accessible through WeatherSystem interface to a text file. But I could not get it to work - while the addon is added, the text file is not created on load. Could you guide me on what i am missing?
The c++ code looks like this:
#include "stdafx.h"
#include "initpdk.h"
#include "PdkPlugin.h"
#include <WinError.h>
#include <string>
#include<iostream>
using std::cerr;
using std::endl;
#include<fstream>
using std:fstream;
#include<cstdlib>
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)
};
void SystemReadyCallback::Invoke(IParameterListV400* pParams)
{
if (!pParams)
{
return;
}
const static wchar_t* S_NAME = L"Virtual Cockpit - View 00";
// This callback indicate that Prepar3D finish loading
UINT64 messageID = pParams->GetParameter(0).Value;
if (messageID == EVENT_MESSAGE_LOADING_COMPLETE)
{
ofstream outdata;
// Get the window plugin system
//CComPtr<IWindowPluginSystem> spPluginSystem = PdkServices::GetWindowPluginSystem();
CComPtr<IWeatherSystemV430> weatherSystem = PdkServices::GetWeatherSystem();
if (weatherSystem != NULL)
{
outdata.open("weatherdata.txt");
outdata << weatherSystem->GetGlobalBaroPressure() << endl;
outdata.close();
}
}
}
static SystemReadyCallback* s_pSystemReadyCallback = nullptr;
extern "C" __declspec(dllexport) void __stdcall DLLStart(__in __notnull IPdk* pPdk)
{
PdkServices::Init(pPdk);
printf("P3d initialized");
s_pSystemReadyCallback = new SystemReadyCallback();
PdkServices::GetEventService()->RegisterCallback(EVENTID_Message, s_pSystemReadyCallback);
}
extern "C" __declspec(dllexport) void __stdcall DLLStop(void)
{
if (s_pSystemReadyCallback != nullptr)
{
s_pSystemReadyCallback = nullptr;
}
PdkServices::Shutdown();
}
My add-on.xml file:
<?xml version="1.0" encoding="utf-8" ?>
- <SimBase.Document Type="AddOnXml" version="4,3" id="add-on">
<AddOn.Name>MyAddOn</AddOn.Name>
<AddOn.Description>My Add-on developed by My Company.</AddOn.Description>
- <AddOn.Component>
<Category>Weather</Category>
<Path>weather</Path>
</AddOn.Component>
- <AddOn.Component>
<Category>DLL</Category>
<Path>C:\Program Files\Lockheed Martin\Prepar3D v4 SDK 4.3.29.25520\PDK\x64\Debug\weather.dll</Path>
<DLLType>PDK</DLLType>
</AddOn.Component>
</SimBase.Document>
Thank you
I attempted to make a small weather add-on which would write the variable values accessible through WeatherSystem interface to a text file. But I could not get it to work - while the addon is added, the text file is not created on load. Could you guide me on what i am missing?
The c++ code looks like this:
#include "stdafx.h"
#include "initpdk.h"
#include "PdkPlugin.h"
#include <WinError.h>
#include <string>
#include<iostream>
using std::cerr;
using std::endl;
#include<fstream>
using std:fstream;
#include<cstdlib>
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)
};
void SystemReadyCallback::Invoke(IParameterListV400* pParams)
{
if (!pParams)
{
return;
}
const static wchar_t* S_NAME = L"Virtual Cockpit - View 00";
// This callback indicate that Prepar3D finish loading
UINT64 messageID = pParams->GetParameter(0).Value;
if (messageID == EVENT_MESSAGE_LOADING_COMPLETE)
{
ofstream outdata;
// Get the window plugin system
//CComPtr<IWindowPluginSystem> spPluginSystem = PdkServices::GetWindowPluginSystem();
CComPtr<IWeatherSystemV430> weatherSystem = PdkServices::GetWeatherSystem();
if (weatherSystem != NULL)
{
outdata.open("weatherdata.txt");
outdata << weatherSystem->GetGlobalBaroPressure() << endl;
outdata.close();
}
}
}
static SystemReadyCallback* s_pSystemReadyCallback = nullptr;
extern "C" __declspec(dllexport) void __stdcall DLLStart(__in __notnull IPdk* pPdk)
{
PdkServices::Init(pPdk);
printf("P3d initialized");
s_pSystemReadyCallback = new SystemReadyCallback();
PdkServices::GetEventService()->RegisterCallback(EVENTID_Message, s_pSystemReadyCallback);
}
extern "C" __declspec(dllexport) void __stdcall DLLStop(void)
{
if (s_pSystemReadyCallback != nullptr)
{
s_pSystemReadyCallback = nullptr;
}
PdkServices::Shutdown();
}
My add-on.xml file:
<?xml version="1.0" encoding="utf-8" ?>
- <SimBase.Document Type="AddOnXml" version="4,3" id="add-on">
<AddOn.Name>MyAddOn</AddOn.Name>
<AddOn.Description>My Add-on developed by My Company.</AddOn.Description>
- <AddOn.Component>
<Category>Weather</Category>
<Path>weather</Path>
</AddOn.Component>
- <AddOn.Component>
<Category>DLL</Category>
<Path>C:\Program Files\Lockheed Martin\Prepar3D v4 SDK 4.3.29.25520\PDK\x64\Debug\weather.dll</Path>
<DLLType>PDK</DLLType>
</AddOn.Component>
</SimBase.Document>
Thank you