The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: peaslee on April 01, 2009, 05:20:39 PM

Title: How to use API calls that are not in Library
Post by: peaslee on April 01, 2009, 05:20:39 PM
Invoking procedures such as GetModuleHandle is easy. But what if I want to make an API call that is not in the Library? For example, GetWindowInfo.

Thanks,

Bruce
Title: Re: How to use API calls that are not in Library
Post by: donkey on April 01, 2009, 05:27:01 PM
GetWindowInfo is in user32.dll while GetModuleHandle is in Kernel32.dll. To use in MASM I think you have to include user32.lib.
Title: Re: How to use API calls that are not in Library
Post by: MichaelW on April 01, 2009, 05:39:06 PM
GetWindowInfo is in the MASM32 user32 library. What appears to be missing from windows.inc and winextra.inc is the WINDOWINFO structure declaration, but you can easily add that to your code (this may not be the latest version, but it should be correct through Windows XP):

    WINDOWINFO STRUCT
      cbSize          DWORD ?
      rcWindow        RECT  <>
      rcClient        RECT  <>
      dwStyle         DWORD ?
      dwExStyle       DWORD ?
      dwWindowStatus  DWORD ?
      cxWindowBorders DWORD ?
      cyWindowBorders DWORD ?
      atomWindowType  ATOM  ?
      wCreatorVersion WORD  ?
    WINDOWINFO ENDS

Title: Re: How to use API calls that are not in Library
Post by: peaslee on April 01, 2009, 06:09:07 PM
Thanks, guys. I now know where to go.
Title: Re: How to use API calls that are not in Library
Post by: kero on April 16, 2009, 12:17:25 PM
Hi, MichaelW

>  but it should be correct through Windows XP
> WINDOWINFO STRUCT (etc)

Try this tiny tester:


.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

WINDOWINFO struct           ; (MISSING in windows.inc)
  cbSize           DWORD ?
  rcWindow         RECT <>
  rcClient         RECT <>
  dwStyle          DWORD ?
  dwExStyle        DWORD ?
  dwWindowStatus   DWORD ?
  cxWindowBorders  UINT  ?
  cyWindowBorders  UINT  ?
  atomWindowType   ATOM  ?
  wCreatorVersion  WORD  ?
WINDOWINFO ends

.data
  ft   db "%8.8lX   ""%s""",13,10,13,10
       db "%8.8lX   GetWindowLong (GWL_EXSTYLE)",13,10
       db "%8.8lX   WINDOWINFO.dwExStyle",0
.data?
  hw   dd ?
  bu   db 128 dup(?)
  buf  db 256 dup(?)
  wi   WINDOWINFO <>
.code
start:
  invoke GetDesktopWindow
  invoke GetWindow,eax,GW_CHILD
  invoke GetWindow,eax,GW_HWNDLAST
  mov hw,eax
  invoke GetClassName,hw,addr bu,127
  mov wi.cbSize,sizeof wi
  invoke GetWindowInfo,hw,addr wi
  invoke GetWindowLong,hw,GWL_EXSTYLE
  invoke wsprintf,addr buf,addr ft,hw,addr bu,eax,wi.dwExStyle
  invoke MessageBox,0,addr buf,0,MB_TOPMOST
  invoke ExitProcess,0
end start


On my XP-pro-sp2  -  WINDOWINFO.dwExStyle  Error:

(http://files.rsdn.ru/42164/wi_exstyle.png)

updated:
special version for lazy :)
Use Ctrl+C to copy info from message box to clipboard. After Ctrl+C :

---------------------------
Ctrl+C
---------------------------
5.1.2600   Service Pack 2

00010086   "Progman"

00000080   GetWindowLong (GWL_EXSTYLE) 
C0000880   WINDOWINFO.dwExStyle
---------------------------
ОК   
---------------------------

Need reports from Win98 (1st OS with WINDOWINFO), 2k, 2k3, Vista, etc.
Thanks.


[attachment deleted by admin]
Title: Re: How to use API calls that are not in Library
Post by: UtillMasm on April 17, 2009, 06:03:56 PM
Vista SP1 error too.
Title: Re: How to use API calls that are not in Library
Post by: MichaelW on April 17, 2009, 08:22:14 PM
The code runs without apparent error under Windows 2000 and XP. Are you perhaps interpreting the "Error" title on the message box as an indication of an error?

MessageBox( hWnd, lpText, lpCaption, uType)

lpCaption - pointer to a null-terminated string that contains the dialog box title. If this parameter is NULL, the default title "Error" is used.
Title: Re: How to use API calls that are not in Library
Post by: donkey on April 18, 2009, 12:13:49 AM
That is not an error, no error dialog in any version of Windows looks like that and since the program does not check for errors it is not an application defined one. The wsprintf command simply takes the data from the data section and formats and displays it...

invoke wsprintf,addr buf,addr ft,hw,addr bu,eax,wi.dwExStyle // addr ft points to the format string in the data section, eax and wi.dwExStyle are simply the values used.

The program is executing properly. If you want to know if there is an error use GetLastError, that's what its meant for.
Title: Re: How to use API calls that are not in Library
Post by: UtillMasm on April 18, 2009, 05:39:05 AM
use GetWindowInfo and GetWindowLong to get dwExStyle value.
but, why the value not equal!

why?, so i think the GetWindowLong API on Windows XP or Vista is error.
Title: Re: How to use API calls that are not in Library
Post by: donkey on April 18, 2009, 05:55:38 AM
It would appear that WS_EX_NOANIMATION and WS_EX_NOACTIVATE are not returned by GetWindowLong, there are others. I saw a list once but didn't bother to bookmark it and can't find it anymore.
Title: Re: How to use API calls that are not in Library
Post by: Farabi on April 18, 2009, 07:45:01 AM
You can use "GetProcAddress" for any avilable library that are not include on MASM.
Title: Re: How to use API calls that are not in Library
Post by: kero on April 19, 2009, 11:48:31 AM
UtillMasm
> why?, so i think the GetWindowLong API on Windows XP or Vista is error.

You forget about GetWindowInfo and WINDOWINFO.dwExStyle, why? :)
GetWindowLong isn't guilty, see code of "winfo_err" example. All 3 windows there must be equal, but...

donkey
> It would appear that WS_EX_NOANIMATION and WS_EX_NOACTIVATE are not returned by GetWindowLong, there are others.

No, GetWindowLong isn't guilty again :)
Look: (or WS_EX_NOANIMATION,WS_EX_NOACTIVATE) = (or 04000000,08000000) = 0C000000, but WINDOWINFO.dwExStyle shows something like C0000000 :).
Also MSDN/"WS_EX_NOANIMATION": "This style is supported only by Windows CE".

---
TO MODERATOR: is it possible to move my off-topic about WINDOWINFO.dwExStyle to new detached topic in "The Workshop" forum ?


[attachment deleted by admin]