Opc.Ua.WindowsCertificateStore.EnumStoreCallback C# (CSharp) Method

EnumStoreCallback() static private method

static private EnumStoreCallback ( IntPtr pvSystemStore, uint dwFlags, IntPtr pStoreInfo, IntPtr pvReserved, IntPtr pvArg ) : int
pvSystemStore System.IntPtr
dwFlags uint
pStoreInfo System.IntPtr
pvReserved System.IntPtr
pvArg System.IntPtr
return int
        static int EnumStoreCallback(
           IntPtr pvSystemStore,
           uint   dwFlags,
           IntPtr pStoreInfo,
           IntPtr pvReserved,
           IntPtr pvArg)
        {
            try
            {
	            EnumResults pResults = (EnumResults)Marshal.PtrToStructure(pvArg, typeof(EnumResults));
                
                IntPtr[] names = null;

	            if (pResults.Count >= pResults.Capacity)
	            {
		            int dwCapacity = pResults.Capacity+10;
                    names = new IntPtr[dwCapacity];

                    if (pResults.Count > 0 && pResults.Names != IntPtr.Zero)
                    {
                        Marshal.Copy(pResults.Names, names, 0, pResults.Count);  
                        Marshal.FreeHGlobal(pResults.Names);
                        pResults.Names = IntPtr.Zero;
                    }

		            pResults.Names = Marshal.AllocHGlobal(dwCapacity*IntPtr.Size);
		            pResults.Capacity = dwCapacity;
	            }
                else
                {
                    names = new IntPtr[pResults.Capacity];
                    Marshal.Copy(pResults.Names, names, 0, pResults.Count);
                }

                string storeName = Marshal.PtrToStringUni(pvSystemStore);
                names[pResults.Count++] = DuplicateString(storeName);

                Marshal.Copy(names, 0, pResults.Names, pResults.Count);
                Marshal.StructureToPtr(pResults, pvArg, false);

	            return 1;
            }
            catch (Exception)
            {
                return 0;
            }
        }
        #endregion