char GetCharFromWrapper(IntPtr sw, int index) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getChar"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: getChar"); } getChar getChar = (getChar)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getChar)); return(getChar(sw, index)); }
int DisposeDLLObject(IntPtr v) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "dispose"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: dispose"); } dispose dispose = (dispose)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(dispose)); return(dispose(v)); }
int GetWrapperLen(IntPtr sw) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "len"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: len"); } len len = (len)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(len)); return(len(sw)); }
public int AnomalyCount() { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getAnomalyCount"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: getAnomalyCount"); } getAnomalyCount getAnomalyCount = (getAnomalyCount)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getAnomalyCount)); return(getAnomalyCount(AnomalyReportVector)); }
public int GetTimeStep(int index) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getTimeStep"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: getTimeStep"); } getTimeStep getTimeStep = (getTimeStep)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getTimeStep)); return(getTimeStep(AnomalyReportVector, index)); }
void AddCharToWrapper(IntPtr sw, char c) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "addCharToString"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: addCharToString"); } addCharToString addCharToString = (addCharToString)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(addCharToString)); addCharToString(sw, c); }
public void Detect(string names, string filename) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "detect"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: detect"); } detect detect = (detect)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(detect)); IntPtr sw_filename = sw_string(filename); IntPtr sw_names = sw_string(names); AnomalyReportVector = detect(this.detector, sw_names, names.Length, sw_filename); DisposeDLLObject(sw_filename); DisposeDLLObject(sw_names); }
public void LearnNormal(string names, string filename) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "learn"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: learn"); } learn learn = (learn)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(learn)); IntPtr sw_filename = sw_string(filename); IntPtr sw_names = sw_string(names); learn(detector, sw_names, names.Length, sw_filename); DisposeDLLObject(sw_filename); DisposeDLLObject(sw_names); }
public AnomalyDetector() { pDll = DllLoader.LoadLibrary(dll_path); if (pDll == IntPtr.Zero) { Trace.WriteLine("Error loading dll"); } IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "createSimpleAnomalyDetectorInstance"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function"); } createSimpleAnomalyDetectorInstance createSimpleAnomalyDetectorInstance = (createSimpleAnomalyDetectorInstance)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(createSimpleAnomalyDetectorInstance)); this.detector = createSimpleAnomalyDetectorInstance(); }
public IntPtr sw_string(string s) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "createString"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: createString"); } createString createString = (createString)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(createString)); IntPtr STR = createString(s.Length); for (int i = 0; i < s.Length; i++) { AddCharToWrapper(STR, s[i]); } return(STR); }
public string GetFunction(int index) { IntPtr pAddressOfFunctionToCall = DllLoader.GetProcAddress(pDll, "getFunc"); if (pAddressOfFunctionToCall == IntPtr.Zero) { Trace.WriteLine("Error loading function: getFunc"); } getFunc getFunc = (getFunc)Marshal.GetDelegateForFunctionPointer(pAddressOfFunctionToCall, typeof(getFunc)); IntPtr sw = getFunc(AnomalyReportVector, index); string s = ""; for (int i = 0; i < GetWrapperLen(sw); i++) { s += GetCharFromWrapper(sw, i); } DisposeDLLObject(sw); return(s); }
public void UnloadDlls() { DllLoader.FreeLibrary(pDll); }