Signature is not Interop compatible - calling c methods from c#

-1

Im trying to make use of interop functionality to use create a .net wrapper for the c written pigpio library. However i seem to be stuck with the following error: "Cannot marshal 'parameter #2': Signature is not Interop compatible". The C method has the following signature:

int gpioWaveAddGeneric(unsigned numPulses, gpioPulse_t *pulses);

where as gpioPulse_t is:

typedef struct
{
   uint32_t gpioOn;
   uint32_t gpioOff;
   uint32_t usDelay;
} gpioPulse_t;

i assumed that this would be the signature to invoke the class:

 [DllImport(Constants.PiGpioLibrary, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gpioWaveAddGeneric")]
 public static extern int GpioWaveAddGeneric(uint numPulses, [In, MarshalAs(UnmanagedType.LPArray)] GpioPulse[] pulses);

where GpioPulse[] is

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class GpioPulse
{
    private BitMask m_GpioOn;
    private BitMask m_GpioOff;
    private uint m_DelayMicroseconds;
    public BitMask GpioOn { get => m_GpioOn; set => m_GpioOn = value; }
    public BitMask GpioOff { get => m_GpioOff; set => m_GpioOff = value; }
    public uint DurationMicroSecs { get => m_DelayMicroseconds; set => m_DelayMicroseconds = value; }
}

and BitMask:

[Flags]
public enum BitMask : uint
{
    None = 0x00000000,
    All = 0xFFFFFFFF,
    Bit00 = 0x00000001,
    Bit01 = 0x00000002,
    Bit02 = 0x00000004,
    Bit03 = 0x00000008,
}

any Idea what I am doing wrong?

c#
c
interop
marshalling
asked on Stack Overflow Jan 15, 2019 by Rene Steen

1 Answer

0

Solution: uint32_t in C# would just be a uint, so your GpioPulse C# class should just be as simple as the C version, e.g. public struct GpioPulse { uint gpioOn; uint gpioOff; uint usDelay; }

answered on Stack Overflow Jan 17, 2019 by Rene Steen

User contributions licensed under CC BY-SA 3.0