m0nk3yI3unz Posted June 27, 2007 Share Posted June 27, 2007 Heya. I know I might get flamed for this, but oh well For about a year now, Ive been programming with AutoIt. Ive seen tons of scripts calling DLLs using works like hwnd (which I now know is some sort of window handle), ubyte, struct, return, blah blah blah. This has been a topic of which I have not been able to grasp (its not that Im lazy, I just dont get it. I think its because I havn't found a true GUIDE for them. I know WHAT they are, but not how to use them...), which is weird, for I've learned almost all of the commands for AutoIt, Im halfway through the includes, and Ive started making tons of UDF's (which I have not had a chance to post yet). Anyways, this lack of knowledge is just holding me back. Please don't tell me to go read up on DLL's because I already have, and about 6 out of the 7 all said the same thing, which was that they are like the AutoIt includes: shell files with certain functions. Here are my questions (If there is an article that explains all these, PLEASE point me to it): 1) How do you know what functions are in what DLL's? I've opened them up in ResHacker to see if they had like accelerator(sp?) numbers (Im quite savvy with the ASM stuff o.O but I have messed up some apps every once in a while) but most of them just have the version info. Opening them up in NotePad just gives me the regular non-notepad construction of international letters and rectangles (you know, for the asian fonts or w/e). Ive tried everything I can to get a list of functions or whatever I need from DLLs with no success. (Now I know you're going to laugh at me and say "Well, duh; do this that and the other" and we'll all laugh about it xD) 2) What do all of AutoIt's calldll (Or whatever it is) parameters mean? Struct, Byte (well THAT I know... but it also has to do with DLLs but I have no idea how) 3) Is it really worth it to learn about DLLs in the first place?? Any help would be greatly appreciated!! Thx! -m0nkey_I3unz P.S. Wish me luck here. Just joined, and hopefully I'll be of help to peoples :3 Monkeh. Link to comment Share on other sites More sharing options...
lod3n Posted June 28, 2007 Share Posted June 28, 2007 (edited) m0nk3y_I3unz,I don't know too much myself, but I've been where you are, so I can offer some advice. If someone wiser sees a mistake in this post, please correct me.I'll answer #3 first:Answer 3: Is it worth it? Maybe, maybe not. PaulIA has a fantastic addition to AutoIt called Auto3Lib which puts a nicer face on many Windows API DLL calls - and you may find that what you are trying to do has already been done there. If not there, then the forums hold a lot of useful samples which you don't really have to comprehend deeply to get some use out of. That said, if you are trying to do something with AutoIt that no one else has done before, and you know it's just a matter of the the right DllCalls, and you are prepared to spend some time working on it, then yes it's worth it. In many cases, it's simply the only way to get certain things done. But don't kill yourself on it. Just take one step at at a time.Answer 1: ResHacker is for hacking the resources within a file, meaning the images, dialog boxes, text strings, etc. DLLs can hold both "files", and compiled machine code. Simply put, ResHacker focuses on the files in DLLs. That doesn't help you as you're trying to see the available functions, if any. Try Heaventools' PE Explorer instead: http://www.heaventools.com/overview.htm Don't worry that you don't already know this; investigating a DLL in this way is not commonplace. What people usually do is look at the documentation for the DLL instead.Unfortunately, most samples (if any) provided in documentation are not even close to being ready to copy and paste it into a AutoIt script. You usually have to translate the examples from whatever language they give you a sample in, to the AutoIt format, and you have to know a lot about both languages, and general Windows API programming before you can really accomplish anything. Often there is no code sample, so you have to look at the requirements, and figure out how to meet those requirements yourself, often by reading additional documentation.Answer 2: First, take a look at the documentation for DllCall in the help file. But to explain what's going on, just know that there are compiled functions lurking in DLLs. DllCall opens the DLL and executes the desired function, and passes parameters. The first argument of DllCall, after the name of the DLL itself, is the return type of the function you call, and usually it's int. After that, you see the function that you want to call. "dll", "return type", "function" are the only required parameters of DllCall, but it's rarely sufficient to stop there. Must functions you call require some additional parameters.Let's say you want to run the ShowWindow function located in user32.dll. http://msdn2.microsoft.com/en-us/library/ms633548.aspxShowWindow requires two parameters: the window handle (hwnd) and a special number which tells ShowWindow what to do with the said window.A window handle is a special code Windows gives to all windows that exist on your screen, and while they are unique and random, they never change throughout the life of the window, so they are safe to use again and again.That special number/code that ShowWindow uses is usually listed in documentation instead as what appears to be a string. If you want to minimize a window with ShowWindow, the code is called "SW_MINIMIZE". SW_MINIMIZE is what's known as a Constant, which is a variable which never changes. So you can't pass in "SW_MINIMIZE" as the parameter, you have to pass in the number that SW_MINIMIZE represents - in this case it's 6. These constants are arbitrary, and are not listed in Microsoft's documentation, because they assume you will be using it in C++ or something, and so you'd already have those constants defined for you. AutoIt accomplishes the same thing with some standard au3 files that come with it, called Includes. A popular example is GUIConstants.au3. If you go into the AutoIt program files directory, you'll find that one in the Includes subdirectory. Take a look at it, but don't change it. SW_MINIMIZE is kind of a bad example of this as it's actually already built in to AutoIt as the macro @SW_MINIMIZE, but if it wasn't and it wasn't in an include somewhere, you could define the constant yourself with a command like $SW_MINIMIZE = 6. So knowing what you know now, you could minimize windows calculator with the following two commands:$hwnd = WinGetHandle("Calculator")DllCall("user32.dll","int","ShowWindow","hwnd",$hwnd,"int",6)Structs are another kind of parameter you can use. Think of them as an Array, but defined in Windows' memory instead of AutoIt's memory. If you have a multivalue array that you need to pass to an external function, but that array was locked up in AutoIt, the function inside the DLL could never get to it. Instead, you allocate some shared external memory with DllStructCreate, which returns to you a code which allows you to fill that struct with data using DllStructSetData. When you do the DllCall though, that code is not useful all by itself. You need to send a the actual RAM address of the struct instead, which is done with DllStructGetPtr, which can find that address (called a Pointer - the clue in documentation is when you see something like "ptrSomething" listed as a parameter) using the code returned by DllStructCreate. Some functions actually fill the structs you pass them with data which you'll then need to read. Reading data back out of a struct is done with DllStructGetData.I hope this gives you enough to get started - and I would have killed for this information about 3 months ago. My advice is to start small and work your way up. Take a look at the examples you find on the forum, and pick them apart, piece by piece. It's NOT obvious, but you can pick it up.I've been fiddling with it myself for just a few months, and I still feel like I have a long way to go. But it can be worth it, especially if you can get help when you need it:http://www.autoitscript.com/forum/index.php?showtopic=47651 Edited June 28, 2007 by lod3n [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
Pithikos Posted January 3, 2008 Share Posted January 3, 2008 m0nk3y_I3unz,I don't know too much myself, but I've been where you are, so I can offer some advice. If someone wiser sees a mistake in this post, please correct me.I'll answer #3 first:Answer 3: Is it worth it? Maybe, maybe not. PaulIA has a fantastic addition to AutoIt called Auto3Lib which puts a nicer face on many Windows API DLL calls - and you may find that what you are trying to do has already been done there. If not there, then the forums hold a lot of useful samples which you don't really have to comprehend deeply to get some use out of. That said, if you are trying to do something with AutoIt that no one else has done before, and you know it's just a matter of the the right DllCalls, and you are prepared to spend some time working on it, then yes it's worth it. In many cases, it's simply the only way to get certain things done. But don't kill yourself on it. Just take one step at at a time.Answer 1: ResHacker is for hacking the resources within a file, meaning the images, dialog boxes, text strings, etc. DLLs can hold both "files", and compiled machine code. Simply put, ResHacker focuses on the files in DLLs. That doesn't help you as you're trying to see the available functions, if any. Try Heaventools' PE Explorer instead: http://www.heaventools.com/overview.htm Don't worry that you don't already know this; investigating a DLL in this way is not commonplace. What people usually do is look at the documentation for the DLL instead.Unfortunately, most samples (if any) provided in documentation are not even close to being ready to copy and paste it into a AutoIt script. You usually have to translate the examples from whatever language they give you a sample in, to the AutoIt format, and you have to know a lot about both languages, and general Windows API programming before you can really accomplish anything. Often there is no code sample, so you have to look at the requirements, and figure out how to meet those requirements yourself, often by reading additional documentation.Answer 2: First, take a look at the documentation for DllCall in the help file. But to explain what's going on, just know that there are compiled functions lurking in DLLs. DllCall opens the DLL and executes the desired function, and passes parameters. The first argument of DllCall, after the name of the DLL itself, is the return type of the function you call, and usually it's int. After that, you see the function that you want to call. "dll", "return type", "function" are the only required parameters of DllCall, but it's rarely sufficient to stop there. Must functions you call require some additional parameters.Let's say you want to run the ShowWindow function located in user32.dll. http://msdn2.microsoft.com/en-us/library/ms633548.aspxShowWindow requires two parameters: the window handle (hwnd) and a special number which tells ShowWindow what to do with the said window.A window handle is a special code Windows gives to all windows that exist on your screen, and while they are unique and random, they never change throughout the life of the window, so they are safe to use again and again.That special number/code that ShowWindow uses is usually listed in documentation instead as what appears to be a string. If you want to minimize a window with ShowWindow, the code is called "SW_MINIMIZE". SW_MINIMIZE is what's known as a Constant, which is a variable which never changes. So you can't pass in "SW_MINIMIZE" as the parameter, you have to pass in the number that SW_MINIMIZE represents - in this case it's 6. These constants are arbitrary, and are not listed in Microsoft's documentation, because they assume you will be using it in C++ or something, and so you'd already have those constants defined for you. AutoIt accomplishes the same thing with some standard au3 files that come with it, called Includes. A popular example is GUIConstants.au3. If you go into the AutoIt program files directory, you'll find that one in the Includes subdirectory. Take a look at it, but don't change it. SW_MINIMIZE is kind of a bad example of this as it's actually already built in to AutoIt as the macro @SW_MINIMIZE, but if it wasn't and it wasn't in an include somewhere, you could define the constant yourself with a command like $SW_MINIMIZE = 6. So knowing what you know now, you could minimize windows calculator with the following two commands:$hwnd = WinGetHandle("Calculator")DllCall("user32.dll","int","ShowWindow","hwnd",$hwnd,"int",6)Structs are another kind of parameter you can use. Think of them as an Array, but defined in Windows' memory instead of AutoIt's memory. If you have a multivalue array that you need to pass to an external function, but that array was locked up in AutoIt, the function inside the DLL could never get to it. Instead, you allocate some shared external memory with DllStructCreate, which returns to you a code which allows you to fill that struct with data using DllStructSetData. When you do the DllCall though, that code is not useful all by itself. You need to send a the actual RAM address of the struct instead, which is done with DllStructGetPtr, which can find that address (called a Pointer - the clue in documentation is when you see something like "ptrSomething" listed as a parameter) using the code returned by DllStructCreate. Some functions actually fill the structs you pass them with data which you'll then need to read. Reading data back out of a struct is done with DllStructGetData.I hope this gives you enough to get started - and I would have killed for this information about 3 months ago. My advice is to start small and work your way up. Take a look at the examples you find on the forum, and pick them apart, piece by piece. It's NOT obvious, but you can pick it up.I've been fiddling with it myself for just a few months, and I still feel like I have a long way to go. But it can be worth it, especially if you can get help when you need it:http://www.autoitscript.com/forum/index.php?showtopic=47651Thanks for this.. it was a big piece of help for myself. I had been searching all around the internet but it was too messy in my mind! Thanks a lot!!! Link to comment Share on other sites More sharing options...
Zedna Posted January 3, 2008 Share Posted January 3, 2008 1) there are many utils for that fo example Dumpbin.exe or link Nirsoft DLL Export Viewer, google for "DLL exports viewer"2) for such details look at www.msdn.com Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
lod3n Posted January 3, 2008 Share Posted January 3, 2008 Thanks for this.. it was a big piece of help for myself. I had been searching all around the internet but it was too messy in my mind! Thanks a lot!!! You are welcome. I'm glad you found it useful! [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now