Easy WinAPI - WinAPI Parser, DllCall with single hotkey
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)
This script will automatically parse MSDN's WinAPI function definition to AHK's DllCall form even with single hotkey.
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
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.
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
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
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.
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.
Maybe this will help me understand Dllcalls etc...
Thanks for the clarification majkinetor.
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.
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
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.
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!
anyone have seen any parsing failure. please let me know
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.
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 :
NTSTATUS ZwOpenFile( OUT PHANDLE FileHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK IoStatusBlock, IN ULONG ShareAccess, IN ULONG OpenOptions );