First of all lets see the following diagram
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 "
); "end of function"
here is the value-type table of C++
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-->doubleif 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
thanks for reading.i wish someone more experienced can guide me to fix possible issues of that tutorial