Reputation: 631
I am trying to import a function from a C Code dll.
the function is
bool AsrLibSetLcdBacklight(ESCORE_LCDBR_CONTROL Ctrl)
there is a enum in the c code
typedef enum
{
ESCORE_LCDBRCTL_UP,
ESCORE_LCDBRCTL_DOWN
} ESCORE_LCDBR_CONTROL_TYPE;
I am trying to call it in Visual studio 2013 in a windows form application using C# with the following code -->
public enum EWestern { ESCORE_LCDBRCTL_UP = 0, ESCORE_LCDBTCTL_DOWN = 1 };
[DllImport("AsrCore.dll",CallingConvention = CallingConvention.Cdecl)]
public static extern bool AsrLibSetLcdBacklight([In]EWestern e);
and calling this function with a button click
private void button4_Click(object sender, EventArgs e)
{
if (AsrLibSetLcdBacklight(EWestern.ESCORE_LCDBTCTL_DOWN))
{
MessageBox.Show("backlight Decreased", "Test");
}
}
When I run the code I get an error about the SystemAccessViolation.
Please let me know what is the issue here, Am i doing it right ? is the syntax good ?
Thank you
Upvotes: 1
Views: 2080
Reputation: 631
What I did to solve the Issue is to make sure that I was using the 64bit platform for my application and running the Application as a administrator.
Upvotes: 1