如何在C#中封送ULONGLONG? 我尝试使用 CalntPoPixePixs/Cuff>获取最后一个唤醒时间,并且复制到OutputBuffer的值是C++中的“代码> ULULLUN >类型,我认为它等同于 ULUN > C</P>

如何在C#中封送ULONGLONG? 我尝试使用 CalntPoPixePixs/Cuff>获取最后一个唤醒时间,并且复制到OutputBuffer的值是C++中的“代码> ULULLUN >类型,我认为它等同于 ULUN > C</P>,c#,interop,marshalling,C#,Interop,Marshalling,当尝试使用封送静态方法时,我看不到获得ulong的方法,只有long。有没有办法获得ulong 我的代码: [DllImport("powrprof.dll", SetLastError = true)] public static extern uint CallNtPowerInformation( InformationLevel informationLevel, IntPtr lpInputBuffer, uint nInputBufferSize, I

当尝试使用
封送
静态方法时,我看不到获得
ulong
的方法,只有
long
。有没有办法获得
ulong

我的代码:

[DllImport("powrprof.dll", SetLastError = true)]
public static extern uint CallNtPowerInformation(
    InformationLevel informationLevel,
    IntPtr lpInputBuffer,
    uint nInputBufferSize,
    IntPtr lpOutpuBuffer,
    nOutputBuffer);

public enum InformationLevel
{
    AdministratorPowerPolicy = 9,
    LastSleepTime = 15,
    LastWakeTime = 14,
    ProcessorInformation = 11,
    ProcessorPowerPolicyAc = 18,
    ProcessorPowerPolicyCurrent = 22,
    ProcessorPowerPolicyDc = 19,
    SystemBatteryState = 5,
    SystemExecutionState = 16,
    SystemPowerCapabilities = 4,
    SystemPowerInformation = 12,
    SystemPowerPolicyAc = 0,
    SystemPowerPolicyCurrent = 8,
    SystemPowerPolicyDc = 1,
    SystemReserveHiberFile = 10,
    VerifyProcessorPowerPolicyAc = 20,
    VerifyProcessorPowerPolicyDc = 21,
    VerifySystemPolicyAc = 2,
    VerifySystemPolicyDc = 3
}

public static ulong GetLastWakeTime()
{
    var lpOutputBuffer = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(ulong)));
    var ntstatusResult = CallNtPowerInformation(
        InformationLevel.LastWakeTime,
        IntPtr.Zero,
        0,
        lpOuputBuffer,
        (uint)Marshal.SizeOf(typeof(ulong)));
    var lastWakeTime = Marshal.ReadInt64(lpOutputBuffer); // This is where ulong should get read from unmanaged memory
    Marshal.FreeHGlobal(lpOutputBuffer);
    return lastWakeTime;
}

封送处理类是CLSCompliant,无符号类型缺少重载。使用
long
很好,在程序出现问题之前,这台机器可以在29227年前启动。@HansPassant,谢谢你的建议。关于29227年的优点:)检查一种可以避免使用封送处理类的技术。因此,在本例中,第2个参数(pass IntPtr.Zero)为
IntPtr
,第4个参数为
out ulong
。封送处理类为CLSCompliant,无符号类型的重载也缺失。使用
long
很好,在程序出现问题之前,这台机器可以在29227年前启动。@HansPassant,谢谢你的建议。关于29227年的优点:)检查一种可以避免使用封送处理类的技术。因此,在本例中,第二个参数为
IntPtr
(传递IntPtr.Zero),第四个参数为
out ulong