AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Easy WinAPI - WinAPI Parser, DllCall with single hotkey

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  

Do you think that Prior VarSetCapacity() should be added automatically?
Yes, i'm tired of adding VarSetCapacity() manually.
90%
 90%  [ 9 ]
No, i don't need it
10%
 10%  [ 1 ]
Total Votes : 10

Author Message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Sun Jul 06, 2008 10:53 pm    Post subject: Easy WinAPI - WinAPI Parser, DllCall with single hotkey Reply with quote

Introduction
    Since using WinAPI requires general knowledges of programming. beginners never gets a chance to use WinAPI although it's possibly most powerful extension of AutoHotkey. When i'm not familar with WinAPI, i've so impressed by Lexikos's StructParser which helps novice to use structs without much Knowledge. so i tried to make something similar that would help beginners to use WinAPI easily. it may not so helpful to experts but at least it'll save your time. Finally, i would like to thank PhiLho for providing useful information about data types between WinAPI and AHK. (i've forgot the link at the moment. i'll add later)


Briefing
    This script will automatically parse MSDN's WinAPI function definition to AHK's DllCall form even with single hotkey.



Showcase



Usage
    1) Connect to MSDN with any browser (double clicking tray icon will do this)
    2) go to any function definition page
    3) select function definition as shown above then press Win + C
    4) parsed text will be stored in clipboard


Features
    1) Data types will be converted from WinAPI to AHK automatically
    2) If a function requires pointer suitable operator will be inserted automatically.
    3) Right DLL File name will be inserted automatically (see list at the bottom)
    4) Entry point (Ansi/Unicode) will be treated too. (always Ansi)
    5) If a function has return value, variable assignment will be inserted by hugarian notation.


Limitations
    1) You have to input arguments manually depend on MSDN definition.
    2) Parser will handle pointers automatically but it's not accurate always. so read MSDN's definition carefully!
    3) It does not parse structs. use Lexiko's StructParser or corrupt's ahkStructLib2 together
    4) It does not lookup Constants, use SKAN's Win32 Constants lookup together


Known Issues
    1) Gdi+ functions are not supported and will not. Take a look at tic's Gdi+ Library
    2) If a function contains CALLBACK, CONST will not work properly.
    3) This script is not perfect. This script does not guarantee at all though will work properly on most functions



Download EasyWinAPI_Rev_004.zip


i'd not post source code for now but later. included free MSDN icon borrowed from Here. Thanks to author
If you've encourtered that script doesn't parses properly report me the function name Thanks.


Supported Dll Files (If you call function that is in any other dll file, you have to type manually)
ADVAPI32.DLL / COMCTR32.DLL / COMDLG32.DLL / GDI32.DLL / GDIPLUS.DLL / IPHLPAPI.DLL / KERNEL32.DLL / MSVCRT.DLL / NTDLL.DLL / PSAPI.DLL / SHELL32.DLL / USER32.DLL / WININET.DLL / WINMM.DLL.

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com


Last edited by heresy on Wed Jul 09, 2008 9:28 am; edited 3 times in total
Back to top
View user's profile Send private message
k3ph



Joined: 21 Jul 2006
Posts: 123

PostPosted: Tue Jul 08, 2008 1:35 am    Post subject: Reply with quote

great
_________________
                                  [ profile | ahk.net | ahk.talk ]
Back to top
View user's profile Send private message
300W



Joined: 12 Jan 2008
Posts: 27

PostPosted: Tue Jul 08, 2008 1:58 am    Post subject: Reply with quote

wow, very nice!! Maybe this will help me understand Dllcalls etc...
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Tue Jul 08, 2008 1:54 pm    Post subject: Reply with quote

300W wrote:
Maybe this will help me understand Dllcalls etc...
Basically, understanding Dllcall/WinAPI needs knowledge of C/C++. i spend about 3 months to understand Dllcall and WinAPI without C/C++ knowledges which is inefficiency. i believe this script will bring you to Dllcall/WinAPI world as quickly as possible even if you never experienced C/C++ before. all you need to do is reading MSDN carefully for arguments and using Lexikos or corrupt's structures helper and SKAN's constants look up tool.
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Tue Jul 08, 2008 2:29 pm    Post subject: Reply with quote

C++ isn't necessary.
Only to better understand COM internals, but Win API is only C.

Thx for this script.
_________________
Back to top
View user's profile Send private message MSN Messenger
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Wed Jul 09, 2008 9:38 am    Post subject: Reply with quote

@majkinetor
Thanks for the clarification majkinetor.

@Everyone
i've added a poll to decide adding prior VarSetCapacity() or not for the case that the DllCall requires pointer to return something. but the problem is that i have no idea to determine the optimal buffer size for each functions. sometimes it'll waste of memory sometimes returned Strings will be truncated due to the unoptimal capacity of the Var. however i think it'll be helpful to beginners. it'll look like below. let me hear your opinion about this issue.

Code:
VarSetCapacity(lpFilename, 128) ;128 is static capacity for all the functions
dwRes := DllCall("GetModuleFileNameA", "UInt", hModule, "Str", lpFilename, "UInt", nSize) ;nSize should be 128 but it will not be treated though

_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Fry



Joined: 01 Nov 2007
Posts: 610

PostPosted: Mon Jul 14, 2008 7:07 pm    Post subject: Reply with quote

I vote Yes!

This is probably the best tool here on AHK imo.

With this script i can easily use the Windows API something i could now do before!

Thanks!!!
_________________
check out my site
www.eliteknifesquad.com
Back to top
View user's profile Send private message
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Sat Jul 19, 2008 5:52 am    Post subject: Reply with quote

Fry wrote:
I vote Yes!

This is probably the best tool here on AHK imo.

With this script i can easily use the Windows API something i could now do before!

Thanks!!!
Thank you Fry, i'm glad that it helped you so. i'd like to see more opinions about VarSetCapacity() until i have clear solution. This tool can be more useful when used with SKAN's constants lookup tool and Lexikos's StructParser tool. with these tools, you can parse almost everything of Win32 API.

anyone have seen any parsing failure. please let me know
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 912
Location: The Interwebs

PostPosted: Sat Jul 19, 2008 5:56 am    Post subject: Reply with quote

Ooh. Definitely like this script! DllCalls have always been tricky for me... =x

Also, vote is yes. I hate having to set variable capacity
Back to top
View user's profile Send private message AIM Address
heresy



Joined: 11 Mar 2008
Posts: 291

PostPosted: Sat Jul 19, 2008 6:00 am    Post subject: Reply with quote

Krogdor wrote:
Ooh. Definitely like this script! DllCalls have always been tricky for me... =x

Also, vote is yes. I hate having to set variable capacity


Thanks for your opinion Krogdor. i might add On/Off trigger for adding VarSetCapacity(). cause some people doesn't like it.
_________________
Easy WinAPI - Dive into Windows API World
Benchmark your AutoHotkey skills at PlayAHK.com
Back to top
View user's profile Send private message
SKAN



Joined: 26 Dec 2005
Posts: 5888

PostPosted: Thu Jul 24, 2008 12:22 pm    Post subject: Reply with quote

Very nice! Very Happy

Any idea of releasing the code in near future?
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
Azerty



Joined: 19 Dec 2006
Posts: 72
Location: France

PostPosted: Fri Aug 01, 2008 10:33 am    Post subject: Reply with quote

Nice one Heresy.

As Skan asked, would you mind sharing code ?

For vote : Yes with ability to disable through right click on systray icon.

Further suggestion, I know it's not officially supported, but digging deeper might help : parsing WDK.

Try parsing this :
Code:
NTSTATUS
  ZwOpenFile(
    OUT PHANDLE  FileHandle,
    IN ACCESS_MASK  DesiredAccess,
    IN POBJECT_ATTRIBUTES  ObjectAttributes,
    OUT PIO_STATUS_BLOCK  IoStatusBlock,
    IN ULONG  ShareAccess,
    IN ULONG  OpenOptions
    );

_________________
Assembler-coded MCode.ahk ASCII85.ahk library
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group