getting pointer to COM Interface

  • Thread starter Thread starter Anuchen
  • Start date Start date
A

Anuchen

Guest
Hello,

I need to access the functions of Prepar3d's PDK's IWeatherStation from C# code.

Weather System Service

For this the code I have started writing looks like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;


namespace ExampleCOM
{
[ComVisible(true)]
enum CLOUD_COVER { CLOUD_CLEAR, CLOUD_FEW_1_8, CLOUD_FEW_2_8, CLOUD_SCATTERED_3_8, CLOUD_SCATTERED_4_8,
CLOUD_BROKEN_5_8, CLOUD_BROKEN_6_8, CLOUD_BROKEN_7_8, CLOUD_OVERCAST_8_8, CLOUD_C_MAX};
enum CLOUD_TOP { CLOUDTOP_FLAT, CLOUDTOP_ROUND, CLOUDTOP_ANVIL, CLOUDTOP_TOP_MAx };
enum CLOUD_TYPE { CLOUD_NONE, CLOUD_CIRRUS, CLOUD_STRATUS, CLOUD_CUMULUS, CLOUD_CUMULONIMBUS, CLOUD_VISIBILITY_LAYER,
CLOUD_THUNDERSTORM, CLOUD_MAX};
enum ICINGRATE { ICINGRATE_NONE, ICINGRATE_TRACE, ICINGRATE_LIGHT, ICINGRATE_MODERATE, ICINGRATE_SEVERE, ICINGRATE_MAX };
enum PRECIPRATE {PRECIPRATE_VLOW, PRECIPRATE_LOW , PRECIPRATE_MODERATE , PRECIPRATE_HIGH , PRECIPRATE_VHIGH ,
PRECIPRATE_MAX};
enum PRECIPTYPE { PRECIP_NONE, PRECIP_RAIN, PRECIP_SNOW, PRECIP_MAX };
enum TURBULANCE { TURB_NONE, TURB_LIGHT , TURB_MODERATE , TURB_HEAVY,TURB_SEVERE ,TURB_MAX};
enum WINDSHEAR { WINDSHEAR_GRADUAL, WINDSHEAR_MODERATE, WINDSHEAR_STEEP, WINDSHEAR_INSTANTANEOUS, WINDSHEAR_MAX };
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]

public struct CloudLayer
{
CLOUD_COVER eCloudCover;
CLOUD_TOP eCloudTop;
CLOUD_TYPE eCloudType;
ICINGRATE eIcingRate;
PRECIPRATE ePrecipRate;
PRECIPTYPE ePrecipType;
TURBULANCE eTurbulance;
float fCloudBase;
float fCloudDeviation;
float fCloudTops;
float fPrecipBase;

};

public struct TempLayer
{
float fAlt;
float fDewPoint;
float fRange;
float fTemp;
};

public struct WindAloftLayer
{
TURBULANCE eTurb;
WINDSHEAR eWindShear;
float fAlt;
float fDirection;
float fGusts;
float fSpeed;
float fVariance;

};
public struct VisibilityLayer
{
float fBase;
float fTops;
float fVis;
};



[Guid("e4452b96-16ba-4e82-9342-aa37af1f5c26")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IWeatherStationV430 // IUnknown base interface is implicit
{

bool IsValid();
float GetSurfaceWind();
void SetSurfaceWind(float aVal);
float GetBaroPressure();
void SetBaroPressure(float aVal);
int GetCloudLayerCount();
void GetCloudAtIndex(ref int uIndex, out CloudLayer aLayer);
void AddNewCloudToTower(ref CloudLayer aLayer);
void RemoveCloudLayerFromTower(int uIndex);
void ClearAllCloudsAtTower();
void GetTempLayerCount();
void GetTempLayerAtIndex(ref uint uIndex, out TempLayer aLayer);
void AddNewTempToTower(ref TempLayer aLayer);
void RemoveTempLayerFromTower(int uIndex);
void ClearAllTempLayersFromTower();
uint GetAloftLayerCount();
void GetAloftLayerAtIndex(ref uint uIndex, out WindAloftLayer aLayer);
void AddNewAloftToTower(ref WindAloftLayer aLayer);
void RemoveAloftLayerFromTower(int uIndex);
void ClearAllWindLayersFromTower();
void GetVisibilityLayerCount();
void GetVisibilityLayerAtIndex(ref uint uIndex, out VisibilityLayer aLayer);
void AddNewVisToTower(ref VisibilityLayer aLayer);
void RemoveVisLayerFromTower(int uIndex);
void ClearAllVisLayersFromTower();
}

[Guid("10B5A161-F18D-412B-8CD4-6513574F9CEA")]
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(IWeatherStationV430))]
public class COMClass:IWeatherStationV430
{

//CComPtr<IWeatherStationV430> weatherStation;
IntPtr weatherStation = Marshal.GetComInterfaceForObject(new COMClass(),typeof(COMClass));



public bool IsValid()
{
bool valid = weatherStation->isValid();

}



}




}



I do not know so far if this is the correct approach. As I start to implement the methods by invoking them, I get an error "* or -> operator must be applied only to pointers". And I do not see any of the declared methods appearing on prompt; what is shown is IsEquals(),GetHashCode()...toPointer() etc.


What should i do to resolve this and access the methods declared in IWeatherStationV430 interface?

Continue reading...
 
Back
Top