public static unsafe string QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None) { // If we ever resize over this value something got really wrong const int maximumRealisticSize = 1 * 1024 * 2014; int size = 255; do { fixed(char *buffer = new char[size]) { bool success = QueryFullProcessImageName(hProcess, dwFlags, buffer, ref size); if (success) { return(new string(buffer, 0, size)); } var lastError = GetLastError(); if (lastError != Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER) { lastError.ThrowOnError(); } } size *= 2; }while (size < maximumRealisticSize); throw new InvalidOperationException( $"QueryFullProcessImageName is expecting a buffer of more than {maximumRealisticSize} bytes"); }
public static string QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None) { // If we ever resize over this value something got really wrong const int maximumRealisticSize = 1 * 1024 * 2014; var buffer = new StringBuilder(255); do { int size = buffer.Capacity; bool success = QueryFullProcessImageName(hProcess, dwFlags, buffer, ref size); if (success) { return(buffer.ToString()); } buffer.Capacity = buffer.Capacity * 2; }while (buffer.Capacity < maximumRealisticSize); throw new InvalidOperationException( $"QueryFullProcessImageName is expecting a buffer of more than {maximumRealisticSize} bytes"); }
public static extern bool QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags, StringBuilder lpExeName, ref int lpdwSize);
public static string QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None) { // If we ever resize over this value something got really wrong const int maximumRealisticSize = 1 * 1024 * 2014; var buffer = new StringBuilder(255); do { int size = buffer.Capacity; bool success = QueryFullProcessImageName(hProcess, dwFlags, buffer, ref size); if (success) { return buffer.ToString(); } buffer.Capacity = buffer.Capacity * 2; } while (buffer.Capacity < maximumRealisticSize); throw new InvalidOperationException( $"QueryFullProcessImageName is expecting a buffer of more than {maximumRealisticSize} bytes"); }
public bool QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags, StringBuilder lpExeName, ref uint lpdwSize) => QueryFullProcessImageName(hProcess, dwFlags, lpExeName, ref lpdwSize);
public static unsafe string QueryFullProcessImageName( SafeObjectHandle hProcess, QueryFullProcessImageNameFlags dwFlags = QueryFullProcessImageNameFlags.None) { // If we ever resize over this value something got really wrong const int maximumRealisticSize = 1 * 1024 * 2014; int size = 255; do { fixed (char* buffer = new char[size]) { bool success = QueryFullProcessImageName(hProcess, dwFlags, buffer, ref size); if (success) { return new string(buffer, 0, size); } var lastError = GetLastError(); if (lastError != Win32ErrorCode.ERROR_INSUFFICIENT_BUFFER) { lastError.ThrowOnError(); } } size *= 2; } while (size < maximumRealisticSize); throw new InvalidOperationException( $"QueryFullProcessImageName is expecting a buffer of more than {maximumRealisticSize} bytes"); }