I'm trying to come up with a "library" of methods that my main app will be using. Right now I have a Functions.cs file like this:
SAT.dll functions return me a string of multiple variables separated with pipe ("|"). To use that information on the main application, I'm using a string.split method to extract the variables.
Is there a way to set up a method so that calling SATFuncoes.ConsultarStatusOperacional("1234") would return me a string with all the variables, but calling SATFuncoes.ConsultarStatusOperacional("1234").Variable2(); return me only resultados[1], SATFuncoes.ConsultarStatusOperacional("1234").Variable3(); return resultados[2]?
The number of variables are always known and their types are always expected as well.
C#:
namespace SAT
{
public class SATFuncoes
{
[DllImport("C:\\SAT\\SAT.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr ConsultarStatusOperacional(int numeroSessao, [MarshalAs(UnmanagedType.LPStr)] string codigoDeAtivacao);
public static string ConsultarStatusOperacional(string codAtiv)
{
int numSessao = GerarCodigoNumerico(int.Parse(DateTime.Now.ToString("HHmmss"))); //This is just a method to generate a random 6 digit int based on current time
IntPtr ptr = SATFuncoes.ConsultarStatusOperacional(numSessao, codAtiv); //Calls the method provided by SAT.dll
string resultado = Marshal.PtrToStringAnsi(ptr); // writes the result to the string
String[] resultados = resultado.Split('|'); // splits the result into an array of strings
return resultado;//returns me the whole string
SAT.dll functions return me a string of multiple variables separated with pipe ("|"). To use that information on the main application, I'm using a string.split method to extract the variables.
Is there a way to set up a method so that calling SATFuncoes.ConsultarStatusOperacional("1234") would return me a string with all the variables, but calling SATFuncoes.ConsultarStatusOperacional("1234").Variable2(); return me only resultados[1], SATFuncoes.ConsultarStatusOperacional("1234").Variable3(); return resultados[2]?
The number of variables are always known and their types are always expected as well.
Last edited: