예제 #1
0
        private void WritePropertySet()
        {
            Debug.Assert(0 < PropertyCount, "PropertyCount - zero size");
            Debug.Assert(IntPtr.Zero != nativePropertySet, "ReadPropertySet - no memory");
            Debug.Assert(currentPropertySetIndex < totalPropertySetCount, "WritePropertySet too far");
            if ((currentPropertySetIndex < totalPropertySetCount) && (IntPtr.Zero != nativePropertySet))   // guard against memory overflow

            {
                int    byteCount = PropertyCount * ODB.SizeOf_tagDBPROP;
                IntPtr ptr       = ADP.IntPtrOffset(nativePropertySet, currentPropertySetIndex * ODB.SizeOf_tagDBPROPSET);
                try {
                    rgProperties = Marshal.AllocCoTaskMem(byteCount);
                    SafeNativeMethods.ZeroMemory(rgProperties, byteCount);
#if DEBUG
                    ODB.TraceData_Alloc(rgProperties, "DBPropSet - properties");
#endif
                    Marshal.WriteIntPtr(ptr, 0, rgProperties);
                    Marshal.WriteInt32(ptr, IntPtr.Size, cProperties);

                    IntPtr tmp = ADP.IntPtrOffset(ptr, IntPtr.Size + 4);
                    Marshal.StructureToPtr(guidPropertySet, tmp, false /*deleteold*/);
                }
                catch (Exception e) {
                    Marshal.WriteIntPtr(ptr, 0, IntPtr.Zero); // clear rgProperties
                    Marshal.WriteInt32(ptr, IntPtr.Size, 0);  // clear cProperties
                    Marshal.FreeCoTaskMem(rgProperties);      // FreeCoTaskMem protects itself from IntPtr.Zero
                    rgProperties = IntPtr.Zero;
                    cProperties  = 0;
                    throw e;
                }

                currentPropertySetIndex++;
                currentPropertyIndex = 0;
                GC.KeepAlive(this);
            }
        }