private void ReadIndexedValues(IntPtr subGroupGuidPtr, IntPtr settingGuidPtr) { indexedSettings = new List <IndexedSetting>(); uint returnCode = 0; UInt32 type = 0; IntPtr buffer = IntPtr.Zero; UInt32 possibleSettingIndex = 0; uint bufferSize = 1000; try { buffer = Marshal.AllocHGlobal(1000); while (0 == NativeMethods.PowerReadPossibleValue( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, ref type, possibleSettingIndex, buffer, ref bufferSize)) { IndexedSetting setting = new IndexedSetting(); bufferSize = 1000; returnCode = NativeMethods.PowerReadPossibleFriendlyName( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, possibleSettingIndex, buffer, ref bufferSize); setting.name = Marshal.PtrToStringUni(buffer); bufferSize = 1000; returnCode = NativeMethods.PowerReadPossibleDescription( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, possibleSettingIndex, buffer, ref bufferSize); setting.description = Marshal.PtrToStringUni(buffer); indexedSettings.Add(setting); ++possibleSettingIndex; bufferSize = 1000; } } catch (Exception exception) { throw new PowerManagerException(exception.Message, exception); } finally { Marshal.FreeHGlobal(buffer); } }
public StandaloneConfig() { AppSettings = new IndexedSetting(GetAppSetting); ConnectionStrings = new IndexedSetting(GetConnectionString); }
private void ReadIndexedValues(IntPtr subGroupGuidPtr, IntPtr settingGuidPtr) { indexedSettings = new List<IndexedSetting>(); uint returnCode = 0; UInt32 type = 0; IntPtr buffer = IntPtr.Zero; UInt32 possibleSettingIndex = 0; uint bufferSize = 1000; try { buffer = Marshal.AllocHGlobal(1000); while( 0 == NativeMethods.PowerReadPossibleValue( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, ref type, possibleSettingIndex, buffer, ref bufferSize) ) { IndexedSetting setting = new IndexedSetting(); bufferSize = 1000; returnCode = NativeMethods.PowerReadPossibleFriendlyName( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, possibleSettingIndex, buffer, ref bufferSize); setting.name = Marshal.PtrToStringUni(buffer); bufferSize = 1000; returnCode = NativeMethods.PowerReadPossibleDescription( IntPtr.Zero, subGroupGuidPtr, settingGuidPtr, possibleSettingIndex, buffer, ref bufferSize); setting.description = Marshal.PtrToStringUni(buffer); indexedSettings.Add( setting ); ++possibleSettingIndex; bufferSize = 1000; } } catch (Exception exception) { throw new PowerManagerException(exception.Message, exception); } finally { Marshal.FreeHGlobal(buffer); } }