I can managed dll. This dll contains method such return custom structure.
Method and Structure
[DllImport("powrprof.dll")]
private static extern uint CallNtPowerInformation(
int InformationLevel,
IntPtr lpInputBuffer,
int nInputBufferSize,
ref SystemPowerInformation spi,
int nOutputBufferSize
);
public SystemPowerInformation GetSystemPowerInformation()
{
SystemPowerInformation spi = new SystemPowerInformation();
CallNtPowerInformation(12,
IntPtr.Zero,
0,
ref spi,
Marshal.SizeOf(spi));
return spi;
}
[ComVisible(true)]
[StructLayout(LayoutKind.Sequential)]
[Guid("A79B0F9F-00C7-46C8-A3AE-D371E09ADB0C")]
public struct SystemPowerInformation
{
public uint MaxIdlenessAllowed;
public uint Idleness;
public uint TimeRemaining;
public byte CoolingMode;
}
VbScript
set calc = CreateObject("PowerStateManagement.PowerStateManagement")
sleepTime = calc.GetLastSleepTime()
WScript.Echo(sleepTime)
wakeTime = calc.GetLastWakeTime()
WScript.Echo(wakeTime)
spi = calc.GetSystemPowerInformation()
WScript.Echo(spi.TimeRemaining)
I have exception when I run this script.
0x800a01a8 - Microsoft VBScript runtime error: Object required: 'spi'
But if GetSystemPowerInformation method rewrite as return spi.TimeRemaining
then this script return correct TimeRemaining value
Why I can't return structure, only structure's field?
set
keyword? ieSet spi = calc.GetSystemPowerInformation()
– oracle certified professional