• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dapplo / Dapplo.Windows / 22231723592

20 Feb 2026 04:16PM UTC coverage: 33.416% (-0.07%) from 33.49%
22231723592

push

github

Lakritzator
Small fixes for tests and namespaces

611 of 1948 branches covered (31.37%)

Branch coverage included in aggregate %.

2 of 8 new or added lines in 2 files covered. (25.0%)

231 existing lines in 16 files now uncovered.

1668 of 4872 relevant lines covered (34.24%)

30.47 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Dapplo.Windows.Kernel32/PsAPI.cs
1
// Copyright (c) Dapplo and contributors. All rights reserved.
2
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
using System;
4
using System.Diagnostics;
5
using System.Runtime.InteropServices;
6

7
namespace Dapplo.Windows.Kernel32;
8

9
/// <summary>
10
///     Description of PsAPI.
11
/// </summary>
12
public static class PsApi
13
{
14
    private const string PSAPIDll = "psapi.dll";
15
    /// <summary>
16
    /// Removes as many pages as possible from the working set of the specified process.
17
    /// </summary>
18
    /// <param name="hProcess">A handle to the process. The handle must have the PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION access right and the PROCESS_SET_QUOTA access right. For more information, see Process Security and Access Rights.</param>
19
    /// <returns>If the function succeeds, the return value is nonzero.
20
    /// If the function fails, the return value is zero. To get extended error information, call GetLastError.</returns>
21
    [DllImport(PSAPIDll, SetLastError = true)]
22
    private static extern int EmptyWorkingSet(IntPtr hProcess);
23

24
    /// <summary>
25
    ///     Removes as many pages as possible from the current process.
26
    /// </summary>
27
    public static void EmptyWorkingSet()
28
    {
29
        using (var currentProcess = Process.GetCurrentProcess())
×
30
        {
31
            EmptyWorkingSet(currentProcess.Handle);
×
32
        }
×
33
    }
×
34

35
    /// <summary>
36
    /// Retrieves the fully qualified path for the file containing the specified module.
37
    /// </summary>
38
    /// <param name="hProcess">IntPtr, A handle to the process that contains the module.</param>
39
    /// <param name="hModule">IntPtr A handle to the module. If this parameter is NULL, GetModuleFileNameEx returns the path of the executable file of the process specified in hProcess.</param>
40
    /// <returns>string</returns>
41
    public static string GetModuleFilename(IntPtr hProcess, IntPtr hModule)
42
    {
43
        unsafe
44
        {
45
            const int capacity = 512;
UNCOV
46
            var pathBuffer = stackalloc char[capacity];
×
UNCOV
47
            var nrCharacters = PsApi.GetModuleFileNameEx(hProcess, hModule, pathBuffer, capacity);
×
UNCOV
48
            if (nrCharacters > 0)
×
49
            {
UNCOV
50
                return new string(pathBuffer, 0, nrCharacters);
×
51
            }
52

53
            return null;
×
54
        }
55
    }
56

57
    /// <summary>
58
    /// Retrieves the fully qualified path for the file containing the specified module.
59
    /// </summary>
60
    /// <param name="hProcess">IntPtr, A handle to the process that contains the module.</param>
61
    /// <returns>string</returns>
62
    public static string GetProcessImageFileName(IntPtr hProcess)
63
    {
64
        unsafe
65
        {
66
            const int capacity = 512;
67
            var pathBuffer = stackalloc char[capacity];
×
68
            var nrCharacters = GetProcessImageFileName(hProcess, pathBuffer, capacity);
×
69
            if (nrCharacters > 0)
×
70
            {
71
                return new string(pathBuffer, 0, nrCharacters);
×
72
            }
73

74
            return null;
×
75
        }
76
    }
77

78
    /// <summary>
79
    /// Retrieves the fully qualified path for the file containing the specified module.
80
    /// </summary>
81
    /// <param name="hProcess">IntPtr, A handle to the process that contains the module.</param>
82
    /// <param name="hModule">IntPtr A handle to the module. If this parameter is NULL, GetModuleFileNameEx returns the path of the executable file of the process specified in hProcess.</param>
83
    /// <param name="lpFilename">char * that receives the full path to the executable file.</param>
84
    /// <param name="nSize">uint</param>
85
    /// <returns>uint If the function succeeds, the return value specifies the length of the string copied to the buffer.</returns>
86
    [DllImport(PSAPIDll, SetLastError = true, CharSet = CharSet.Unicode)]
87
    private static extern unsafe int GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, [Out] char * lpFilename, int nSize);
88

89
    /// <summary>
90
    /// Retrieves the name of the executable file for the specified process.
91
    /// </summary>
92
    /// <param name="hProcess">IntPtr, A handle to the process that contains the module.</param>
93
    /// <param name="lpImageFileName">char * that receives the full path to the executable file.</param>
94
    /// <param name="nSize">int</param>
95
    /// <returns>If the function succeeds, the return value specifies the length of the string copied to the buffer</returns>
96
    [DllImport(PSAPIDll, SetLastError = true, CharSet = CharSet.Unicode)]
97
    public static extern unsafe int GetProcessImageFileName(IntPtr hProcess, [Out] char * lpImageFileName, int nSize);
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc