How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

20 May 2019, 09:50

Hello Friends..

I am using ahk since 2013. Although I am not from programming background, I am quite curious to learn ahk deeper. I want to learn more advanced stuff in ahk like dllcall. I am so impressed by ahk that i have started taking tuition for C, C++ and JAVA etc.

In this tread it has been told that for learning dllcall and advanced stuff one needs to have the knowledge of C++
https://autohotkey.com/board/topic/88313-my-dllcall-tutorial-for-beginnersmessagebox/page-1

In the above link, it has been taught by step by step process how to show msgbox using Dllcall. It refers to this msdn page-
https://docs.microsoft.com/en-us/windows/desktop/api/Winuser/nf-winuser-messagebox
which clearly mentions some msgbox function in c++, but there is no such kind of thing in c++

I have covered all most all the topics of c++, but there is not any single mention of windows API or Dll files. Most of the topics of c++ which i covered, are these-

Code: Select all

Lecture-1 Introduction to C++ Part 1 
Lecture-1 Introduction to C++ Part 2 
Lecture-1 Introduction to C++ Part 3 
Lecture-1 Introduction to C++ Part 4 
Lecture-1 Introduction to C++ Part 5 
Lecture-2 Identifiers Part 1 
Lecture-2 Identifiers Part 2 
Lecture-3 Input output Part 1 
Lecture-4 Reference Variables in C++ Part 1 
Lecture-5 Function in C++ Part 1 
Lecture-5 Function in C++ Part 2 
Lecture-5 Function in C++ Part 3 
Lecture-5 Function in C++ Part 4 
Lecture-6 Structure in C++ Part 1 
Lecture-6 Structure in C++ Part 2  
Lecture-6 Structure in C++ Part 3 
Lecture-6 Structure in C++ Part 4 
Lecture-6 Structure in C++ part 5 
Lecture-7 Classes and Objects in C++ Part 1 
Lecture-7 Classes and Objects in C++ Part 2 
Lecture-7 Classes and Objects in C++ Part 3 
Lecture-8 Static Members in C++ Part 1 
Lecture-8 Static Members in C++ Part 2 
Lecture-9 Constructor in C++ Part 1 
Lecture-9 Constructor in C++ Part 2 
Lecture-9 Constructor in C++ Part 3 
Lecture-10 Destructor in C++ Part 1 
Lecture-11 Operator overloading in C++ Part 1 
Lecture-11 Operator Overloading in C++ Part 2 
Lecture-11 Operator Overloading in C++ Part 3 
Lecture-12 Friend Function in C++ Part 1 
Lecture-12 Friend Function in C++ Part 2 
Lecture-12 Friend Function in C++ Part 3 
Lecture-12 Friend Function in C++ Part 4 
Lecture-12 Friend Function in C++ Part 5 
Lecture-12 Friend Function in C++ Part 6 Hindi)
Lecture-13 Inheritance in C++ Part 1 
Lecture-13 Inheritance in C++ Part 2 
Lecture-13 Inheritance in C++ Part 3 
Lecture-14 Constructor and Destructor in Inheritance in C++ Part 1 
Hybrid Inheritance | Diamond Problem | Disinheritance | Virtual Base class | Virtual inheritance
Lecture-15 this pointer in C++ Part 1 
Lecture-16 new and delete in C++ Part 1 
Lecture-17 Method Overriding in C++ Part 1 
Lecture-18 Virtual Function in C++ Part 1 
Lecture-18 Virtual Function in C++ Part 2 
Lecture-19 Abstract Class in C++ Part 1 
Lecture-20 Template in C++ Part 1 
Lecture-20 Template in C++ Part 2 
Lecture-21 File Handling in C++ Part 1 
Lecture-21 File Handling in C++ Part 2 
Lecture-21 File Handling in C++ Part 3 
tellg and tellp in C++ language Hindi 
seekg and seekp functions in C++ Hindi 
Lecture-22 Initializers in C++ 
Lecture-23 Deep Copy and Shallow Copy in C++ 
Lecture-24 Type Conversion Primitive to class type in C++ 
Lecture-25 Type Conversion Class type to primitive type in C++ 
Lecture-26 Type Conversion one class type to another class type in C++ 
Lecture-27 Exception Handling in C++ 
Lecture-28 Dynamic Constructor in C++ 
Lecture-29 namespace in C++ Part 1 of 2 
Lecture-29 namespace in C++ Part 2 of 2 
Lecture-30 Virtual Destructor in C++ 
Lecture-31 Nested Class in C++ 
Lecture-32 Introduction to STL in C++ 
Lecture-33 STL Containers in C++ 
Lecture-34 Array in STL in C++ 
Lecture-35 pair in STL in C++ 
Lecture-36 Tuple in STL in C++ 
Lecture-37 Vector Class in STL in C++ 
Lecture-38 List class in STL in C++ 
Lecture-39 map class in STL in C++ 
Lecture-40 string class in C++ Part 1 
Lecture-40 string class in C++ Part 2 
Encapsulation in Object Oriented Programming
Polymorphism in Object Oriented Programming
Private Constructor in C++

Undoubtedly, I learnt a lot about the use of classes by learning c++, but there is no mention of Dll files or windows api in c++.

Please guide me what should I do to learn more advanced stuff in ahk? Am I learning wrong language (c++)? Is there any other language which I should learn to grasp more advanced stuff? After learning c++ I am thinking to learn JAVA and then Python.

kindly help and guide.

Thanks a lot...
I don't normally code as I don't code normally.
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

20 May 2019, 10:17

With that message box example (and with most of autohotkey), although you use code similar to C,C++ you are actually calling the windows api. For example the regular msgbox for autohotkey just has the command to call on that api in a simple way. In c++ you have to access it manually, which is why there is no function in c++. The same can be said about the rest of the autohtokey controls, they are accessing the windows api code and calling those functions, not c++ standard functions. If you look at c++ coding with gui's (example being QT Creator), all you are doing is calling their api's, which can call windows api. But personally (and take this with a grain of salt) I don't think needing DllCalls is necessary since autohotkey is already doing it for you (but there are some small cases where you do need to call it like when you need to do mouse movements, but the program doesn't accept the autohotkey version so you send the dll version instead). Honestly I would worry more about classes and functions in terms of advanced features than anything else.
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

21 May 2019, 02:05

MannyKSoSo wrote:
20 May 2019, 10:17
With that message box example (and with most of autohotkey), although you use code similar to C,C++ you are actually calling the windows api. For example the regular msgbox for autohotkey just has the command to call on that api in a simple way. In c++ you have to access it manually, which is why there is no function in c++. The same can be said about the rest of the autohtokey controls, they are accessing the windows api code and calling those functions, not c++ standard functions. If you look at c++ coding with gui's (example being QT Creator), all you are doing is calling their api's, which can call windows api. But personally (and take this with a grain of salt) I don't think needing DllCalls is necessary since autohotkey is already doing it for you (but there are some small cases where you do need to call it like when you need to do mouse movements, but the program doesn't accept the autohotkey version so you send the dll version instead). Honestly I would worry more about classes and functions in terms of advanced features than anything else.

Thanks dear MannyKSoSo for your kind reply...


Please tell me which language is more similar to ahk? I mean what should i learn to go deeper in ahk?

I think there are so many things which we can not do using native ahk commands and functions and for that we need to use dllcall. For example, I created a simple gui which contains three edit boxes. I was wanting- the color of edit box which has input focus should change to yellow. This can not be done by native ahk command and functions. So, i ask a question on ahk forum-https://www.autohotkey.com/boards/viewtopic.php?p=277394#p277394

Teadrinker replied to my question and provided these codes-

Code: Select all

backColor := 0xFFFF00

Gui Add, Edit, x183 y57 w205 h51 +hwndhEdit1, Edit 1
SetEditColor(hEdit1, backColor)
Gui Add, Edit, x184 y128 w205 h51, Edit 2
Gui Add, Edit, x185 y199 w205 h51, Edit 3
OnMessage( 0x111, Func("WM_COMMAND").Bind(backColor) )
Gui Show, w547 h338, Window
Return

WM_COMMAND(clr, wp, lp) {
   static EN_SETFOCUS := 0x100, EN_KILLFOCUS := 0x200
   if (wp >> 16 = EN_SETFOCUS)
      SetEditColor(lp, clr)
   if (wp >> 16 = EN_KILLFOCUS)
      SetEditColor(lp)
}

SetEditColor(hEdit, b_color_rgb := "", f_color_rgb := 0) {
   static arr := [], _ := OnMessage( 0x133, Func("WM_CTLCOLOREDIT").Bind(arr) )
   
   if arr.HasKey(hEdit)
      DllCall("DeleteObject", Ptr, arr[hEdit, "hBrush"])
   if (b_color_rgb = "")
      arr.Delete(hEdit)
   else {
      for k, v in ["b", "f"]
         %v%_color_bgr := DllCall("Ws2_32\ntohl", UInt, %v%_color_rgb << 8, UInt)
      hBrush := DllCall("CreateSolidBrush", UInt, b_color_bgr, Ptr)
      arr[hEdit] := {b_color: b_color_bgr, f_color: f_color_bgr, hBrush: hBrush}
   }
   WinSet, Redraw,, ahk_id %hEdit%
}

WM_CTLCOLOREDIT(arr, hDC, hEdit) {
   if !arr.HasKey(hEdit)
      Return
   
   DllCall("SetBkColor"  , Ptr, hDC, UInt, arr[hEdit, "b_color"])
   DllCall("SetTextColor", Ptr, hDC, UInt, arr[hEdit, "f_color"])
   Return arr[hEdit, "hBrush"]
}
The codes are running fine. You can see that he used dllcall so much in above codes and i don't understand these codes at all. So, I mean to say in almost all the things which we can not do by straight forward methods, needs the knowledge of advanced stuff. That's why, I am eager to learn more advanced stuff.

Please help and guide.

Thanks...
I don't normally code as I don't code normally.
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

21 May 2019, 05:04

For the start you don't need much C++ knowledge, because for many of the plain Windows API functions some C knowlede is enough. You should start to learn about C data types, structures and data alignment. Then you need to know where to find the MS documentation. I frequently use the following links as entries:

https://docs.microsoft.com/en-us/windows/desktop/windows-application-ui-development -> windows
https://docs.microsoft.com/en-us/windows/desktop/Controls/individual-control-info -> common controls
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773177(v=vs.85).aspx -> Windows shell
https://docs.microsoft.com/en-us/windows/desktop/WinProg/windows-data-types -> basic data types
https://docs.microsoft.com/en-us/windows/desktop/gdi/windows-gdi -> GDI
https://docs.microsoft.com/en-us/windows/desktop/Debug/system-error-codes -> Windows error codes

They may show you what the functions called by DllCall() are designed to do.

In case of DeleteObject() a Google search for deleteobject will lead you to DeleteObject function (wingdi.h) | Microsoft Docs
User avatar
Sabestian Caine
Posts: 528
Joined: 12 Apr 2015, 03:53

Re: How to learn DllCall and more advanced stuff in AHK as there is no mention of Dll files and Windows API in C++?

22 May 2019, 00:35

just me wrote:
21 May 2019, 05:04
For the start you don't need much C++ knowledge, because for many of the plain Windows API functions some C knowlede is enough. You should start to learn about C data types, structures and data alignment. Then you need to know where to find the MS documentation. I frequently use the following links as entries:

https://docs.microsoft.com/en-us/windows/desktop/windows-application-ui-development -> windows
https://docs.microsoft.com/en-us/windows/desktop/Controls/individual-control-info -> common controls
https://msdn.microsoft.com/en-us/library/windows/desktop/bb773177(v=vs.85).aspx -> Windows shell
https://docs.microsoft.com/en-us/windows/desktop/WinProg/windows-data-types -> basic data types
https://docs.microsoft.com/en-us/windows/desktop/gdi/windows-gdi -> GDI
https://docs.microsoft.com/en-us/windows/desktop/Debug/system-error-codes -> Windows error codes

They may show you what the functions called by DllCall() are designed to do.

In case of DeleteObject() a Google search for deleteobject will lead you to DeleteObject function (wingdi.h) | Microsoft Docs

Thanks a lot dear just me...

Dear just me, as you mentioned that I should learn C data types, structures and data alignment, so please tell me that in which language i can learn those in best way? Now, I'll start taking classes for JAVA. Please tell me would JAVA help me to learn those things? Please help and guide.. Thanks dear just me...
I don't normally code as I don't code normally.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: wilkster and 324 guests