News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

How to use API calls that are not in Library

Started by peaslee, April 01, 2009, 05:20:39 PM

Previous topic - Next topic

peaslee

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
Bruce Peaslee
"Reality is a crutch for those who can't do drugs."

donkey

GetWindowInfo is in user32.dll while GetModuleHandle is in Kernel32.dll. To use in MASM I think you have to include user32.lib.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

MichaelW

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

eschew obfuscation

peaslee

Bruce Peaslee
"Reality is a crutch for those who can't do drugs."

kero

#4
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:



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]

UtillMasm


MichaelW

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.
eschew obfuscation

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

UtillMasm

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.

donkey

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.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Farabi

You can use "GetProcAddress" for any avilable library that are not include on MASM.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

kero

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]