This is feeling so Backwards to me..
This is a simplified version of the DLL i made ->
http://www.pgp-prote.../help/MyDLL.zip
using System.IO;
using System.IO.Pipes;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
namespace PGPDLL
{
public class MyDLL
{
private static bool ValidComPort = false;
private static bool ValidConfig = false;
private static StreamWriter MyWriter;
private static StreamReader MyReader;
private static NamedPipeClientStream MyIPCPipe;
/// <summary>
/// Returns Last Recorded Error Encountered by the DLL.
/// </summary>
public static string InternalErrorReason = "No Error Default";
private static string[] TalkPipeOut()
{
try
{
if (MyIPCPipe.NumberOfServerInstances > 0)
{
string temp;
temp = MyReader.ReadLine();
return temp.Split(':');
}
else
{
return null;
}
}
catch
{
return null;
}
}
private static bool TalkPipeIn(int ComType, string ComData)
{
bool ValidPipeIn = true;
try
{
MyWriter.Write(ComType);
MyWriter.Write(ComData);
}
catch
{
ValidPipeIn = false;
}
return ValidPipeIn;
}
private static void CheckServerOpen(int ServerProcessID)
{
bool ActiveServer = true;
try { ActiveServer = !Process.GetProcessById(ServerProcessID).HasExited; }
catch { ActiveServer = false; }
// If ActiveServer = False,
if (ActiveServer == false)
{
ValidComPort = false;
System.Windows.Forms.MessageBox.Show("Lost Connection To Tester!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
MyIPCPipe.Close();
}
}
static void CheckTimer(object ProcessWatchID)
{
int CheckID = (int)ProcessWatchID;
while (ValidComPort)
{
Thread.Sleep(200);
CheckServerOpen(CheckID);
}
}
private static bool MyWrite(string QstDataOut)
{
bool ValidPipeOut = false;
if (ValidComPort)
try
{
// Send Data
{
MyWriter.AutoFlush = true;
MyWriter.WriteLine(QstDataOut);
}
ValidPipeOut = true;
}
catch
{
ValidPipeOut = false;
}
return ValidPipeOut;
}
private static string MyRead()
{
// Try to open connection with QST Client Pipe Out
// QstRead is used for Getting Data From the Client
string QstReadData = "";
if (ValidComPort)
try
{
QstReadData = MyReader.ReadLine();
}
catch
{
QstReadData = "";
}
return QstReadData;
}
/// <summary>
/// Call to Initilize Comunication with the Server Application
/// </summary>
/// <returns>True if Connected, False if Unable to Connect</returns>
public static bool ServerOpen()
{
if (ValidComPort == false)
{
MyIPCPipe = new NamedPipeClientStream(".", "MySystemsPipe", PipeDirection.InOut, PipeOptions.Asynchronous);
ValidComPort = true;
try { MyIPCPipe.Connect(1000); }
catch (Exception ex)
{
string Erroris;
Erroris = ex.Message;
if (Erroris == "Already in a connected state.")
{
// We're Already Connected, Ignore this error.
ValidComPort = true;
}
else
{
ValidComPort = false;
MessageBox.Show(Erroris);
}
}
}
//QstIPCPipe.Close();
if (ValidComPort)
{
int ServerProcessID = 0;
Thread WatchdogTimer = new Thread(CheckTimer);
string ClientProcessID = System.Diagnostics.Process.GetCurrentProcess().Id.ToString();
MyReader = new StreamReader(MyIPCPipe);
MyWriter = new StreamWriter(MyIPCPipe);
ValidComPort = MyWrite(ClientProcessID);
ServerProcessID = Convert.ToInt16(MyRead());
WatchdogTimer.IsBackground = true;
WatchdogTimer.Start(ServerProcessID);
}
return ValidComPort;
}
/// <summary>
/// Used to Send String array to Server for configurations
/// </summary>
/// <param name="QstTestConfiguration">String Array of Configuration</param>
/// <returns>-1 if Error, Or Total Count of Processed Lines</returns>
public static int QstSendConfig(string[] TestConfigurationReceived)
{
string[] QstTestConfiguration = TestConfigurationReceived;
int FinalValidConfigLines = QstTestConfiguration.Length;
if (ValidComPort && QstTestConfiguration != null)
{
ValidConfig = true;
}
else
{
InternalErrorReason = "Comunication with Server Not Open";
}
return FinalValidConfigLines;
}
/// <summary>
/// Runs a QST Test (Fixed I or Psudo V)
/// Returns a Double Array for Test Results in the Format of double[Sample#,(0=Magnet,1=Test1,2=Test2,3=Test3,4=Test4)]
/// </summary>
/// <param name="TestID1">Calls TestID1 in Configuraton</param>
/// <param name="TestID2">Calls TestID1 in Configuraton</param>
/// <returns>double[TestCount,TestID]</returns>
public static double[,] RunTest(int TestID1, int TestID2)
{
string QstTestSequence = "DummyData";
if (ValidConfig & ValidComPort)
{
if (MyWrite("RUNQST") && MyWrite(QstTestSequence))
{
if (MyRead() == "OK")
return null;
else
return null;
}
}
if (!ValidConfig) InternalErrorReason = "No Valid Configuration Test Not Run";
if (!ValidComPort) InternalErrorReason = "Server Not Found, Test Not Run";
return null;
}
/// <summary>
/// Request And Returns Server Status or what the Last Recorded Error was
/// </summary>
public static string MySystemStatus()
{
string TempStatus = "";
if (!ValidConfig) TempStatus = "No Valid Config ";
if (ValidComPort)
{
if (MyWrite("GETSTATUS"))
{
return TempStatus + MyRead();
}
}
return "Unable to Comunicate";
}
}
}
Compiled in C# Visual studio 2010
It works as I wanted (Full version has more functions, but this version has the .NET Functions that's giving the client the problems)
How do I get it so they can Load this DLL in Visual C++ 6.0 ?