Using Weather Station and Weather System services of PDK API

#1
Hello,

I tried to access P3D's Weather Services provided through PDK API . I made a C# console application that invokes C++ code. The code below:
C++
extern "C" __declspec(dllexport) void __stdcall getPressure()
{
printf("Reading global pressure : ");
CComPtr<IWeatherSystemV430> weatherSystem = PdkServices::GetWeatherSystem();
printf("weather system ");

float pressure = weatherSystem->GetGlobalBaroPressure();
printf("%f", pressure);

}

C#
[DllImport("CameraPDK.dll", CallingConvention = CallingConvention.StdCall)]
public static extern voidgetPressure();


static void Main(string[] args)
{
Console.WriteLine("The global pressure is {0}",getPressure());

}

But i wasn't able ti call the GetGlobalBaroPressure systwm and got a System.Access Violation error at that point

Could anyone guide me towards the right approach?

Thank you
 
#2
The exception i get on debugging is

Exception thrown at 0x000007FEF3CC15EC (CameraPDK.dll)
in Interop.exe: 0xC0000005: Access violation reading location
0xFFFFFFFFFFFFFFFF.
 
#3
Hi, MerAB.
As I know you can not call PDK services from the console application (C++ or C#). You can use it only in PDK plug-ins and "PDK plug-ins must be developed as in-process DLLs" . Your DLL will be loaded by Prepar3D if that is stated as Library in add-on.xml. See PDK examples, they are all dlls.
If you place your getPressure() function in plug-in dll it will give you the same exception. Before you request COM pointer to the object that implement IWeatherSystemV430 interface via PdkServices::GetWeatherSystem() you must initialize PdkServices using pointer to IPDK that your plug-in dll has received in DLLStart function. Look at the SDK example.
Not your C# console application must load or import your dll, but Prepar3D will load your dll at startup and unload it before shutdown.
 
Top