Today was a bit tough.  I had to try and convert the PC-Controls library to C#.net.  At first, things didn’t work out.  I couldn’t load the reference (after a lot of time googling, turns out these unregistered libraries cannot be loaded like a typical library) and I had to load it using the DLLImport functionality in C#.

In order for a library to be loaded with DLLImport, the user must install the library in the windows system.  PC-Controls’ documentation states to save it in the machine’s C:/Windows/System32 folder, however after an hour of testing, it could never find the library.  It would prompt me with the following:

A reference to ‘C:\Program Files (x86)\PC Control Ltd\Autostep\stp.dll’ could not be added.  Please make sure that the file is accessible, and that it is a valid assembly or COM component.

and there was a similar message from Visual Studio debugger when I tried to run it.

However, what did work was putting the dll in the C:\Windows folder.  This makes sense, because this folder can hold on to libraries without them being registered.

Once that was in the right folder, everything ran fine.  Here is the code that I wrote to convert their sample VB code into C#:

http://www.nickpisca.com/BLAST/index.php?title=Stp.dll_DLLImport

Code:
#region // dll setup data
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int InitStp();
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool RunMotor1(
int steps,
int interval,
int direction,
int outputs
);
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool RunMotor2(
int steps,
int interval,
int direction,
int outputs
);
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool StopMotor1(
int outputs);
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool StopMotor2(
int outputs);
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool SetStepMode(
int M1Mode,
int M2Mode);
[DllImport("stp.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool GetCurrentStatus(
out int M1Active,
out int M2Active,
out int M1Steps,
out int M2Steps,
out int Inputs);
#endregion

It had been such a while since I’ve loaded an unregistered dll, that I forgot the System.Runtime.InteropServices requirement.  So now you can’t forget.

Lastly, I wanted to give post a sneak peak of my Pyramid Propagation project I’m coding in the background.  More of this to come as things coalesce. ……

Pyramid Propagation

Pyramid Propagation

f

f