Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Easy WinAPI - WinAPI Parser, DllCall with single hotkey


  • Please log in to reply
20 replies to this topic

Poll: Do you think that Prior VarSetCapacity() should be added automatically? (27 member(s) have cast votes)

Do you think that Prior VarSetCapacity() should be added automatically?

  1. Yes, i'm tired of adding VarSetCapacity() manually. (29 votes [90.62%])

    Percentage of vote: 90.62%

  2. No, i don't need it (3 votes [9.38%])

    Percentage of vote: 9.38%

Vote Guests cannot vote
heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
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
Posted Image

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

danalec
  • Members
  • 225 posts
  • Last active: Oct 03 2014 05:31 PM
  • Joined: 20 Jul 2006
great

                                  [ profile ]


Ice_Tea
  • Members
  • 131 posts
  • Last active: Aug 25 2010 11:11 AM
  • Joined: 12 Jan 2008
wow, very nice!! Maybe this will help me understand Dllcalls etc...

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008

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

majkinetor
  • Moderators
  • 4512 posts
  • Last active: May 20 2019 07:41 AM
  • Joined: 24 May 2006
C++ isn't necessary.
Only to better understand COM internals, but Win API is only C.

Thx for this script.
Posted Image

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008
@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.

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

Fry
  • Members
  • 885 posts
  • Last active: Jan 17 2011 09:57 PM
  • Joined: 01 Nov 2007
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!!!

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008

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

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
Ooh. Definitely like this script! DllCalls have always been tricky for me... =x

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

heresy
  • Members
  • 291 posts
  • Last active: Sep 26 2008 10:47 PM
  • Joined: 11 Mar 2008

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

SKAN
  • Administrators
  • 9115 posts
  • Last active:
  • Joined: 26 Dec 2005
Very nice! :D

Any idea of releasing the code in near future?
kWo4Lk1.png

Azerty
  • Members
  • 72 posts
  • Last active: Jan 16 2009 10:08 AM
  • Joined: 19 Dec 2006
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 :
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

Drugwash
  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008
<!-- m -->http://www.autohotke...ic.php?p=222648<!-- m -->

I hope moderators won't move this one too.

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here


unlogged_automaticman
  • Guests
  • Last active:
  • Joined: --

i'd not post source code for now but later.

Am I allowed to ask what the idea behind that is?

guest3456
  • Guests
  • Last active:
  • Joined: --
this is ridiculous

where is the source?

you really expect us to run your exe?