/// <summary> /// Unmarshals and deallocates a OPCSERVERSTATUS structure. /// </summary> internal static OpcServerStatus GetServerStatus(ref IntPtr pInput, bool deallocate) { OpcServerStatus output = null; if (pInput != IntPtr.Zero) { OpcRcw.Da.OPCSERVERSTATUS status = (OpcRcw.Da.OPCSERVERSTATUS)Marshal.PtrToStructure(pInput, typeof(OpcRcw.Da.OPCSERVERSTATUS)); output = new OpcServerStatus(); output.VendorInfo = status.szVendorInfo; output.ProductVersion = String.Format("{0}.{1}.{2}", status.wMajorVersion, status.wMinorVersion, status.wBuildNumber); output.ServerState = (OpcServerState)status.dwServerState; output.StatusInfo = null; output.StartTime = Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(Convert(status.ftStartTime)); output.CurrentTime = Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(Convert(status.ftCurrentTime)); output.LastUpdateTime = Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(Convert(status.ftLastUpdateTime)); if (deallocate) { Marshal.DestroyStructure(pInput, typeof(OpcRcw.Da.OPCSERVERSTATUS)); Marshal.FreeCoTaskMem(pInput); pInput = IntPtr.Zero; } } return(output); }
/// <summary> /// Allocates and marshals a OPCSERVERSTATUS structure. /// </summary> internal static OpcRcw.Da.OPCSERVERSTATUS GetServerStatus(OpcServerStatus input, int groupCount) { OpcRcw.Da.OPCSERVERSTATUS output = new OpcRcw.Da.OPCSERVERSTATUS(); if (input != null) { output.szVendorInfo = input.VendorInfo; output.wMajorVersion = 0; output.wMinorVersion = 0; output.wBuildNumber = 0; output.dwServerState = (OpcRcw.Da.OPCSERVERSTATE)input.ServerState; output.ftStartTime = Convert(Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(input.StartTime)); output.ftCurrentTime = Convert(Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(input.CurrentTime)); output.ftLastUpdateTime = Convert(Technosoftware.DaAeHdaClient.Com.Interop.GetFILETIME(input.LastUpdateTime)); output.dwBandWidth = -1; output.dwGroupCount = groupCount; output.wReserved = 0; if (input.ProductVersion != null) { string[] versions = input.ProductVersion.Split(new char[] { '.' }); if (versions.Length > 0) { try { output.wMajorVersion = System.Convert.ToInt16(versions[0]); } catch { output.wMajorVersion = 0; } } if (versions.Length > 1) { try { output.wMinorVersion = System.Convert.ToInt16(versions[1]); } catch { output.wMinorVersion = 0; } } output.wBuildNumber = 0; for (int ii = 2; ii < versions.Length; ii++) { try { output.wBuildNumber = (short)(output.wBuildNumber * 100 + System.Convert.ToInt16(versions[ii])); } catch { output.wBuildNumber = 0; break; } } } } return(output); }