Jump to content

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

My DLLcall() tutorial for beginners(Messagebox)


  • Please log in to reply
26 replies to this topic
side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012

First of all lets see the following diagram

2hoahc1.png

We have the green box,the ahk

the red box which is c++

and blue box which includes windows API

 

Users of AHK can expend the limits of AHK's commands by using API's functions.

So dllcall can be used to make possible the things that we cant do with AHKs commands.

Many people (including me)afraid of dllcall.I think it is because of the help file(by my opinion)

 

so lets open help file and get to dll call...

 

the first thing we see is

Result := DllCall("[DllFile\]Function" [, Type1, Arg1, Type2, Arg2, "Cdecl ReturnType"])

Dont panic...

Lets edit that line a little bit

Result := DllCall("DllFile\Function", "Type1", Arg1, "Type2", Arg2,.....,"TypeX",ArgX)

where, X is a natural number...

 

 

So we have a function with some types and some Arg (arguments)

As you can see the type and the args exist in a same amount...

for every arg there is one and only type

 

so that lines look like

CallFromDll("TheDllThatIwant\TheFunctionThatIwant","Type of first value","first value","type of second value","second value"...);

NOTE:

In case we use windows' functions its not necessery to type the whole Directory , like ("%A_scriptDir%\MyFunctions.dll\DoSomething,"type1",arg1,..)

Just use the name of function.the default directory from which DllCall is calling functions is DRIVER_LETTER\Windows\System32

 

 

-So ok side..how can i know what are the supported windows functions?

-its all here

http://msdn.microsof...6(v=vs.85).aspx

 

 

Once we open that website we will see many many categories of functions

We will make the Messagebox.

 

-Side,why should i pop a messagebox via dllcall? Msgbox,  is way easier...

-You should start from easy thing to do the harder

So,at MSDN we go to

 

Dialog Boxes
--Dialog Box Functions
----MessageBox

 

At c++

int WINAPI MessageBox( 
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText, 
_In_opt_ LPCTSTR lpCaption, 
_In_ UINT uType 
);

Lets ...."decrypt" that table

 

TYPE_OF_RETURN_VALUE WINAPI_FUNCTION NAME_OF_IT(

_INPUT_OPTIONAL_ HWND hWnd "HWND is a C++ type of value..we usually say that,in AHK,its an int *Uint*"

_INPUT_OPTIONAL_ LPCTSTR lpText, "as above its a C++ type of value...we usually say that,in AHK,its a string"

_INPUT_OPTIONAL_LPCTSTR lp,Caption

_INPUT_UINT uType          "doesnt contain OPTIONAL so its a necessery input!!! Uint in ahk is ....Uint tongue.png "

); "end of function"

 

 

here is the value-type table of C++

 

xn6fzl.png


i will try to "transfer" C++ types to ahk

 

 

 

char-->Str
short int-->Short
int-->int
long int-->int
bool-->int (Its in helpfile-->)

 

An Int should also be used for each BOOL argument expected by a function (a BOOL value should be either 1 or 0).

 

float-->float
double/long double-->double

if we have an unsigned value,then we add a 'U'
example of unsigned int--> Uint

Hwnd-->int (Also in help file for both)
LPCTSTR-->Str

 

 

So lets get back to our function...

int WINAPI MessageBox(
_In_opt_ HWND hWnd,
_In_opt_ LPCTSTR lpText,
_In_opt_ LPCTSTR lpCaption,
_In_ UINT uType
);

Lets open editor and lets try build our command-function

DllCall("MessageBox",.......)

We dont need full directory as we said.(messagebox is included to user32.dll)

So,we now want 4 values ,that 3 of them are not necessery

As we read to MSDN it says "HWND"...so we get "int"

While reading the meaning of that value we can easily understand that we want that to be '0'

so....

DllCall("MessageBox","Uint",0...)

After that,MSDN is guiding us to write our message in a LPCTSTR value...so we get string value for ahk

DllCall("MessageBox","Uint",0,"Str","This Message is poped through DLLcall",....)

At third value we must type the title of the messagebox in a LPCTSTR value...so we get string value for ahk

DllCall("MessageBox","Uint",0,"Str","This Message is poped through DLLcall","Str","I typed that title",....)

At forth value we see that we MUST type that value(which is int).IT IS necessery...

that value configures the behavor of messagebox

According to what value we insert,we will have other behavor(buttons etc)

 

example

for "0x00000006L" our box will have 3 buttons (Cancel/Try again/Continue)

 

so,

DllCall("MessageBox","Uint",0,"Str","This Message is poped through DLLcall","Str","I typed that title","Uint","0x00000006L"...)

Scrolling down to MSDN we will see that ICON requires "0x00000030L"

Yes but we have already insert our values...so?!???

 

0x00000006L+0x00000030L=0x00000036L

 

At the end we have...

DllCall("MessageBox","Uint",0,"Str","This Message is poped through DLLcall","Str","I typed that title","Uint","0x00000036L")

About return value

 

We already know that it is an integer.So we add our function to a value,show it via msgbox and check whats inside

ReturnValue := DllCall("MessageBox","Uint",0,"Str","This Message is poped through DLLcall","Str","I typed that title","Uint","0x00000036L")
msgbox,%ReturnValue%

As MSDN inform us,the number represents the dialog result.that means,that,this number shows us which button we pressed

 

example

If i press "cancel" the number will be '2'....

etc

 

 

 

So,thats the end smile.png

thanks for reading.i wish someone more experienced can guide me to fix possible issues of that tutorial



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

great



FrostByte
  • Members
  • 148 posts
  • Last active: Sep 16 2015 05:56 PM
  • Joined: 08 Nov 2012

(I'm sure guest3456 knows) I NEEDED THIS EPICALLY.


FrostByte and the Artemis Asylrum® Corporation
View my projects: Artemis Media Player

FrostByte62.com is down. I'll find another place to host my stuff soon...after I get done procrastinating some more. :)


Sjc1000
  • Members
  • 572 posts
  • Last active: Mar 11 2017 11:41 AM
  • Joined: 06 Feb 2012

Thank you for this awesome tutorial side, maybe i will understand these functions now :) 


Sjc1000 - Insert inspirational quote here!

PLEASE find me on the IRC if you have questions. I'm never on the forum anymore.

 


side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012

thanks for everything :)

waiting for your feedback :)



guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011

certainly you should link to the actual DllCall help page in your first post:

http://www.autohotke...nds/DllCall.htm

 

instead of trying to "transfer the types to AHK", you can just link to the DllCall page which has its own table



side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012

certainly you should link to the actual DllCall help page in your first post:

http://www.autohotke...nds/DllCall.htm

 

instead of trying to "transfer the types to AHK", you can just link to the DllCall page which has its own table

 

 

 

there are many thing in help file,about vars...so i decided to make it simplier :)



awannaknow
  • Members
  • 372 posts
  • Last active: Mar 03 2019 05:18 AM
  • Joined: 14 Jun 2009

Thanks a lot for your tut, althought dlls are still way over my skills,  it's great help to progress and a good refresher to know where to find needed references like DllCall help page, microsoft pages, etc . . .


Your scripts online or anything you'll need online for free with 0hna.tk  like: Zero $ Hosting No Ad Free Online Hosting
Remove comments and blank lines in AHK code

side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012
Thanks a lot for your tut, althought dlls are still way over my skills,  it's great help to progress and a good refresher to know where to find needed references like DllCall help page, microsoft pages, etc . . .

 

 

You  are welcome :)

i will post more tutorials soon :)



drozdman
  • Members
  • 17 posts
  • Last active: Dec 05 2015 06:05 AM
  • Joined: 15 Oct 2012

That's cool...

The link to msdn is helpful too...

 

BTW..  Is it possible to insert an image to Explorer window using DLL call in AHK? 

I wanted to use a pin icon for window always on top function. Something what FileBox Extender does. It looks like this http://s1102.beta.ph...29333b.png.html



Coco
  • Members
  • 697 posts
  • Last active: Oct 31 2015 07:26 PM
  • Joined: 27 Jul 2012
I wanted to use a pin icon for window always on top function. Something what FileBox Extender does.

On Windows 7, you will find the icons (pin and unpin) in imageres.dll (nos. 216 and 217)..You can create a small window/GUI with the icon(s) and dock them on the active window every time you call the command...requires some kung-fu coding..icon_razz.gif



side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012
That's cool...

The link to msdn is helpful too...

 

BTW..  Is it possible to insert an image to Explorer window using DLL call in AHK? 

I wanted to use a pin icon for window always on top function. Something what FileBox Extender does. It looks like this http://s1102.beta.ph...29333b.png.html

 

 

=========================

i dont know if that is possible...maybe by calling a dll which included in win7?!!?!?

i dont know how to do it in AHK...

 

(surely know how to do it in C# though)



drozdman
  • Members
  • 17 posts
  • Last active: Dec 05 2015 06:05 AM
  • Joined: 15 Oct 2012

OK... I thought someone could have already done something similar...icon_confused.gif

I'll put it off for a while and study the Windows API List..



side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012
OK... I thought someone could have already done something similar...icon_confused.gif

I'll put it off for a while and study the Windows API List..

 

 

============

well...i dont know...maybe ask at IRC ....i am not the specialist about it



side
  • Members
  • 168 posts
  • Last active: Nov 30 2014 03:41 PM
  • Joined: 01 Nov 2012

Bump