public static void CleanUpNativeData(ref IntPtr pNativeData) { if (pNativeData != IntPtr.Zero) { XSQLDA xsqlda = Marshal2.PtrToStructure <XSQLDA>(pNativeData); Marshal2.DestroyStructure <XSQLDA>(pNativeData); for (var i = 0; i < xsqlda.sqln; i++) { IntPtr ptr = GetIntPtr(pNativeData, ComputeLength(i)); var sqlvar = new XSQLVAR(); MarshalXSQLVARNativeToManaged(ptr, sqlvar, true); if (sqlvar.sqldata != IntPtr.Zero) { Marshal.FreeHGlobal(sqlvar.sqldata); sqlvar.sqldata = IntPtr.Zero; } if (sqlvar.sqlind != IntPtr.Zero) { Marshal.FreeHGlobal(sqlvar.sqlind); sqlvar.sqlind = IntPtr.Zero; } Marshal2.DestroyStructure <XSQLVAR>(ptr); } Marshal.FreeHGlobal(pNativeData); pNativeData = IntPtr.Zero; } }
public byte[] GetSecBufferBytes() { if (pBuffers == IntPtr.Zero) { throw new ObjectDisposedException(nameof(SecBufferDesc)); } SecBuffer secBuffer = Marshal2.PtrToStructure <SecBuffer>(pBuffers); return(secBuffer.GetBytes()); }
public void Dispose() { if (pBuffers != IntPtr.Zero) { SecBuffer secBuffer = Marshal2.PtrToStructure <SecBuffer>(pBuffers); secBuffer.Dispose(); Marshal.FreeHGlobal(pBuffers); pBuffers = IntPtr.Zero; } }
public static Descriptor MarshalNativeToManaged(Charset charset, IntPtr pNativeData, bool fetching) { // Obtain XSQLDA information var xsqlda = Marshal2.PtrToStructure <XSQLDA>(pNativeData); // Create a new Descriptor var descriptor = new Descriptor(xsqlda.sqln) { ActualCount = xsqlda.sqld }; // Obtain XSQLVAR members information var xsqlvar = new XSQLVAR(); for (var i = 0; i < xsqlda.sqln; i++) { var ptr = GetIntPtr(pNativeData, ComputeLength(i)); MarshalXSQLVARNativeToManaged(ptr, xsqlvar); // Map XSQLVAR information to Descriptor descriptor[i].DataType = xsqlvar.sqltype; descriptor[i].NumericScale = xsqlvar.sqlscale; descriptor[i].SubType = xsqlvar.sqlsubtype; descriptor[i].Length = xsqlvar.sqllen; // Decode sqlind value descriptor[i].NullFlag = xsqlvar.sqlind == IntPtr.Zero ? (short)0 : Marshal.ReadInt16(xsqlvar.sqlind); // Set value if (fetching) { if (descriptor[i].NullFlag != -1) { descriptor[i].SetValue(GetBytes(xsqlvar)); } } descriptor[i].Name = GetString(charset, xsqlvar.sqlname, xsqlvar.sqlname_length); descriptor[i].Relation = GetString(charset, xsqlvar.relname, xsqlvar.relname_length); descriptor[i].Owner = GetString(charset, xsqlvar.ownername, xsqlvar.ownername_length); descriptor[i].Alias = GetString(charset, xsqlvar.aliasname, xsqlvar.aliasname_length); } return(descriptor); }
public static void CleanUpNativeData(ref IntPtr pNativeData) { if (pNativeData != IntPtr.Zero) { // Obtain XSQLDA information XSQLDA xsqlda = Marshal2.PtrToStructure <XSQLDA>(pNativeData); // Destroy XSQLDA structure Marshal2.DestroyStructure <XSQLDA>(pNativeData); // Destroy XSQLVAR structures for (var i = 0; i < xsqlda.sqln; i++) { IntPtr ptr = GetIntPtr(pNativeData, ComputeLength(i)); // Free sqldata and sqlind pointers if needed var sqlvar = new XSQLVAR(); MarshalXSQLVARNativeToManaged(ptr, sqlvar, true); if (sqlvar.sqldata != IntPtr.Zero) { Marshal.FreeHGlobal(sqlvar.sqldata); sqlvar.sqldata = IntPtr.Zero; } if (sqlvar.sqlind != IntPtr.Zero) { Marshal.FreeHGlobal(sqlvar.sqlind); sqlvar.sqlind = IntPtr.Zero; } Marshal2.DestroyStructure <XSQLVAR>(ptr); } // Free pointer memory Marshal.FreeHGlobal(pNativeData); pNativeData = IntPtr.Zero; } }