I've been working on a project using C# on a WinCE7 device and I can't seem to be able to figure out how to use an API.dll i've been provided with. The API is used to control the gpio and contains interrupt functions for the input. The documentation I have for the api is very limited and I do not have access to the code itself. I've managed to get everything working using a polling mechanism but i can't seem to set up the interrupt. I've read a lot of articles on msdn and codeproject and browsed through some stack overflow questions but my code still fails. The function I'm trying to use looks like this:
BOOL GpioSetupInterruptPin(HANDLE hGPIO, PIN_GPIO_PORT port, UINT pin, INT_TRIGGER_MODE mode, INT_TRIGGER_POLARITY polarity, LPCWSTR szEventName, BOOL enable);
I've been given the structures for the PORT, TRIGGER_MODE and TRIGGER_POLARITY and the following description for szEventName: "event name of a named event". That is all i've been given for this function and i've been unable to contact the developer. I've found a few questions about using LPCWSTR with pInvoke and the fixes were either setting the CharSet to Charset.Unicode or marshalling as UnmanagedType.LPArray, but i'm note sure the fixes apply for this case. Furthermore, I'm new at event handling in c# and I'm not sure I'm doing that correctly either.
public class StartEventArgs : System.EventArgs
{
private GPIOapi.PIN_GPIO_PORT port;
private uint pin;
public StartEventArgs(GPIOapi.PIN_GPIO_PORT port,uint pin)
{
this.port = port;
this.pin = pin;
}
}
public delegate void StartEventHandler(StartEventArgs e);
public class GPIO_In
{
public event StartEventHandler TriggerDown;
public event StartEventHandler TriggerUp;
protected virtual void OnTriggerDown(StartEventArgs e)
{
if (TriggerDown != null)
TriggerDown(e);
}
protected virtual void OnTriggerUp(StartEventArgs e)
{
if (TriggerUp != null)
TriggerUp(e);
}
public void DoTrigger(GPIOapi.PIN_GPIO_PORT port, uint pin)
{
OnTriggerDown(new StartEventArgs(port, pin));
//....
OnTriggerUp(new StartEventArgs(port, pin));
}
}
private GPIO_In input;
public Form1()
{
InitializeComponent();
input=new GPIO_In();
connect();
}
void connect()
{input.TriggerDown+=new StartEventHandler(this.Check);}
private void Check(StartEventArgs e)
{
GetInput(pin1, port6, pin_level);
}
Does anyone have any idea how to use this function and would they be kind enough to share some of their experience? Thank you. Some of the resources I've tired:
http://msdn.microsoft.com/en-gb/library/aa288459(v=vs.71).aspx
http://msdn.microsoft.com/en-gb/library/aa645739(v=vs.71).aspx
http://stackoverflow.com/questions/7609225/c-to-c-sharp-event-handling
http://stackoverflow.com/questions/17073386/raise-events-in-c-cli-dll-and-consume-in-c-sharp
http://stackoverflow.com/questions/12576944/triggering-event-in-c-sharp-from-c-dll
http://www.codeproject.com/Questions/155043/Raise-C-event-and-catch-in-C
http://stackoverflow.com/questions/2969654/how-to-marshall-a-lpcwstr-to-string-in-c
http://www.codeproject.com/Questions/460787/Which-data-type-in-Csharp-equivalent-with-LPCWSTR
http://msdn.microsoft.com/En-US/library/aa288468(VS.71).aspx#pinvoke_example1
EDIT*: Not sure if I got the title right but to clarify: I want to trigger an event in C# using the above mentioned function (which I believe is written in C++)