Skip to content

Commit

Permalink
refactor(win32-api): use wcharBuffer() instead of BufferTypeFactory()
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jun 28, 2022
1 parent 7a584b1 commit 0069add
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/win32-api/src/data-struct-ext/wingdi.h.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// windows data types struct for ref-struct module https://github.com/TooTallNate/ref-struct
import { DTypes as W } from 'win32-def'

import { BufferTypeFactory } from '../lib/fixed-buffer.js'
import { wcharBuffer } from '../lib/fixed-buffer.js'


/** https://docs.microsoft.com/zh-cn/windows/win32/api/wingdi/ns-wingdi-display_devicew */
export const DISPLAY_DEVICEW = {
cb: W.DWORD,
DeviceName: BufferTypeFactory(32, 'ucs2'),
DeviceString: BufferTypeFactory(128, 'ucs2'),
DeviceName: wcharBuffer(32),
DeviceString: wcharBuffer(128),
StateFlags: W.DWORD,
DeviceID: BufferTypeFactory(128, 'ucs2'),
DeviceKey: BufferTypeFactory(128, 'ucs2'),
DeviceID: wcharBuffer(128),
DeviceKey: wcharBuffer(128),
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,25 @@ describe(fileShortPath(import.meta.url), () => {

const ret = user32.EnumDisplayDevicesW(ref.NULL, 0, dd.ref(), 0)
assert(ret)
const { DeviceName, DeviceString, DeviceID, DeviceKey } = dd
console.log({
const {
DeviceID,
DeviceKey,
DeviceName,
DeviceString,
} = dd
console.log({
DeviceID,
DeviceKey,
DeviceName,
DeviceString,
})
assert(DeviceName.replace(/\0+$/u, '').includes('\\\\.\\DISPLAY1'))
assert(DeviceString.replace(/\0/ug, '').length > 0)
assert(DeviceID.startsWith('PCI\\VEN_') || DeviceID.includes('VMBUS') || DeviceID === '', DeviceID)
assert(typeof DeviceKey === 'string', DeviceKey)
assert(DeviceName === '\\\\.\\DISPLAY1', DeviceName)
assert(DeviceString.length > 0)
const flag = ['Microsoft Hyper-V', 'Intel', 'AMD'].some(val => DeviceString.includes(val))
assert(flag === true, DeviceString)

})

})
Expand Down

0 comments on commit 0069add

Please sign in to comment.