Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Compile Error #29

Open
BobbyShoe opened this issue Dec 29, 2020 · 2 comments
Open

TypeScript Compile Error #29

BobbyShoe opened this issue Dec 29, 2020 · 2 comments

Comments

@BobbyShoe
Copy link

Hello,

I am getting this error when trying to use the win32-api in a typescript file and then compiling it with tsc.

"node_modules/win32-def/dist/lib/ffi.model.d.ts:26:18 - error TS2430: Interface 'FFIBuffer' incorrectly extends interface 'Buffer'.
The types of 'ref(...).readObject' are incompatible between these types.
Type '(offset?: number | undefined) => string' is not assignable to type '(buffer: Buffer, offset?: number | undefined) => Object'.
Types of parameters 'offset' and 'buffer' are incompatible.
Type 'Buffer' is not assignable to type 'number'.

26 export interface FFIBuffer extends Buffer {"

Below is my typescript class. I was basically just trying to run the sample to rename the calculator app. Any suggestions?

Thanks,
Bobby

import { FModel, K, U } from 'win32-api'
import { HANDLE } from 'win32-def/dist/lib/win.model';

export class WinAutomationService {
private knl32: FModel.ExpandFnModel<K.Win32Fns>;
private user32: FModel.ExpandFnModel<U.Win32Fns>;

constructor() {
    this.knl32 = K.load();
    this.user32 = U.load();
}

public setTitle() {
    const title: string = 'Calculator\0';

    const lpszWindow = Buffer.from(title, 'ucs2');
    const hWnd: HANDLE = this.user32.FindWindowExW(0, 0, null, lpszWindow);

    if (typeof hWnd === 'number' && hWnd > 0
        || typeof hWnd === 'bigint' && hWnd > 0
        || typeof hWnd === 'string' && hWnd.length > 0) {
        console.log('buf: ', hWnd)

        // Change title of the Calculator
        const res = this.user32.SetWindowTextW(hWnd, Buffer.from('Node-Calculator\0', 'ucs2'))

        if (!res) {
            console.log('SetWindowTextW failed')
        }
        else {
            console.log('window title changed')
        }
    }
}

}

Also here are all the node modules in my project if there happens to be a conflict here

+-- @electron-forge/[email protected]
+-- @electron-forge/[email protected]
+-- @electron-forge/[email protected]
+-- @electron-forge/[email protected]
+-- @electron-forge/[email protected]
+-- @types/[email protected]
+-- @types/[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

@waitingsong
Copy link
Owner

waitingsong commented Jan 2, 2021

pls try this:

import { K, U } from 'win32-api'

const knl32 = K.load()
const user32 = U.load()

export class WinAutomationService {
  private knl32: typeof knl32;
  private user32: typeof user32;

  constructor() {
    this.knl32 = knl32;
    this.user32 = user32;
  }
  // ....
}

AND this:

const hWnd: HANDLE = this.user32.FindWindowExW(0, 0, null, lpszWindow); // wrong parameter order
const hWnd: HANDLE = this.user32.FindWindowExW(0, 0, lpszWindow, null); // correct

@justanotheranonymoususer

I have the same problem. @BobbyShoe, did you find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants