Question about C# DllImports for K8055 & K8061


A while ago I bought the pre assembled K8055 board and wrote a C# application in MS Visual studio 2008. Since I never had to import a DLL before it was quite a challenge to get it working. (the examples don’t include C#) But thanks to some great forums I found a full set of import instructions for the C# implementation of the ‘K8055D.dll’ which work perfectly.

Now I have switched over to the extended version K8061 and am faced with the same problem of creating import instructions for my C# project to use the ‘K8061_C.dll’. After some searching again I found a full set.

But they are very dissimilar from the ones for the ‘K8055D.dll’ even though in the manual of both boards the API discriptions are similar.

These are some for the ‘K8055D.dll’ that work fine.

[DllImport("k8055d.dll")] public static extern int OpenDevice(int CardAddress); [DllImport("k8055d.dll")] public static extern void CloseDevice(); [DllImport("k8055d.dll")] public static extern int ReadAnalogChannel(int Channel); [DllImport("k8055d.dll")] public static extern void ReadAllAnalog(ref int Data1, ref int Data2); [DllImport("k8055d.dll")] public static extern void OutputAnalogChannel(int Channel, int Data);

And these are some of the ‘K8061_C.dll’ I found but won’t work unless i rewrite alot of my code.

[DllImport("K8061_c.dll")] private static extern unsafe UInt32 OpenDevice(); [DllImport("K8061_c.dll")] private static extern unsafe void CloseDevices(); [DllImport("K8061_c.dll")] private static extern unsafe byte PowerGood(byte CardAddress); [DllImport("K8061_c.dll")] private static extern unsafe byte Connected(byte CardAddress); [DllImport("K8061_c.dll")] private static extern unsafe void ReadVersion(byte CardAddress, ref UInt32 Buffer); [DllImport("K8061_c.dll")] private static extern unsafe void ReadAllAnalog(byte CardAddress, ref UInt32 Buffer);

I figured out that I can change the data-types and remove the unsafe keyword. I tested a few and seemed to work.

But now I’m confused as to which ones are best practice.

I’d be glad to get some more advice on this matter. (if this is the right place to ask)


public static extern int OpenDevice();
public static extern void CloseDevices();
public static extern byte PowerGood(int addr);
public static extern byte Connected(int addr);
public static extern unsafe void ReadVersion(int addr, ref int buffer);
public static extern unsafe void ReadAllAnalog(byte addr, ref int buffer);

The card address is of type int (32-bit signed integer), passing only a byte will corrupt the stack. Some functions return a boolean (1 byte) which is represented here by the byte type. “unsafe keyword (C#)” “DllImportAttribute Class” “ref (C# Reference)” “extern keyword (C#)”