Skip to content

Commit

Permalink
feat(win32-api): breaking change nMaxCount not contains terminal-null
Browse files Browse the repository at this point in the history
  • Loading branch information
waitingsong committed Jul 20, 2022
1 parent fb18c7e commit 151878d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/win32-api/src/func/user32/index.user32.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ export async function user32GetWindowText(

const mod = getMod<Win32Fns>(dllName)

const len = nMaxCount
const len = nMaxCount + 1
const buf = Buffer.alloc(len * 2)

const ret = await mod.GetWindowTextW(hWnd, buf, len)
const ret = await mod.GetWindowTextW(hWnd, buf, nMaxCount)
if (ret > 0) {
const str = ucsBufferToString(buf)
const str = ucsBufferToString(buf, len)
return str
}
return ''
Expand Down
2 changes: 1 addition & 1 deletion packages/win32-api/test/70.user32.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe(fileShortPath(import.meta.url), () => {
// Change title of the Calculator
await user32.SetWindowTextW(hWnd, Buffer.from(title + '\0', 'ucs2'))

const len = title.length + 1
const len = title.length
assert(len > 0)

const text = await user32GetWindowText(hWnd, len)
Expand Down
2 changes: 1 addition & 1 deletion packages/win32-api/test/winspool/502.OpenPrinter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
describe(fileShortPath(import.meta.url), () => {

describe('Should work', () => {
it.only('normal', async () => {
it('normal', async () => {
const name = await winspoolGetDefaultPrinter()
assert(name)
const hWnd = await winspoolOpenPrinter(name)
Expand Down

0 comments on commit 151878d

Please sign in to comment.