Jump to content

Help "FindWindow" DllCall


Recommended Posts

Hi, today I'm following Dealing_with_Dll Tutorial. And I don't know how to put the parameters.

I don't understand what this means.

lpClassName [in, optional]

Type: LPCTSTR

The class name or a class atom created by a previous call to the RegisterClass or RegisterClassEx function. The atom must be in the low-order word of lpClassName; the high-order word must be zero.

If lpClassName points to a string, it specifies the window class name. The class name can be any name registered with RegisterClass or RegisterClassEx, or any of the predefined control-class names.

If lpClassName is NULL, it finds any window whose title matches the lpWindowName parameter.

sorry for my grammar mistakes...

This is my code:

$X = dllcall("user32.dll","HWND","FindWindow","str","str")
        msgbox(0,"",$X)
Link to comment
Share on other sites

A few things:

  • There is no function called Findwindow. You have to specify whether you want to pass ansi or unicode strings, by calling either "FindWindowA" or "FindWindowW" respectively. I am surprised that isn't covered by the tutorial. This is the same for all functions in the winapi that take string parameters (except a few that only allow one or the other), and can be told by the fact they use LPCTSTR (read as: Long Pointer to a constant TCHAR string), TCHAR being either ansi or unicode depending on what is being used. Scroll to the bottom of msdn pages and look for the row in the table saying "Unicode and ANSI names" to see these.
  • DllCall requires parameters as well as type names. Right now you are only passing the types, which makes no sense. Look at the documentation for DllCall again, and you'll see that parameters are given as DllCall("Dll", "Return Type", "Function", "Arg type 1", "Arg 1", "Arg type 2", "Arg 2", ..., "Arg type N", "Arg N")
  • DllCall returns an array, so nothing will show up in the message box. Instead, you can show the return value from the function by reading the first element of the array, or show the entire array using _ArrayDisplay. If you are using the array though, you must check for errors as the return value might now be an array at all if the function fails.
A good reference point is to look at how it has already been implemented in _WinAPI_Findwindow. This will also show you how to deal with the fact that the lpClassName parameter is not necessarily a pointer to a string. Edited by Mat
Link to comment
Share on other sites

Use the AU3Info tool or _WinAPI_GetClassName($hWnd) to get the class name.

$X = DllCall("user32.dll", "HWND", "FindWindow", "str", "Shell_TrayWnd", "str", "")
MsgBox(0, "", "Out: " & $X[0] & @CRLF & "In #1: " & $X[1] & @CRLF & "In #2: " & $X[2])
Link to comment
Share on other sites

Mat

I thought it did not matter if I put"W"or "A" as long as I use "str"or "WSTR" respectively.

thank you so much Kafu

Edited by Danyfirex
Link to comment
Share on other sites

I thought it did not matter if I put"W"or "A" as long as I use "str"or "WSTR" respectively.

You are right (sort of) I hadn't realised that AutoIt automagically adds the 'A' by default. However, if you passed a wstr parameter it would still try and use the ansi version (according to the docs). You can ignore my first point above then. I've just got into the habit of always saying which one I wanted.
Link to comment
Share on other sites

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...