#189985 - 2008-10-02 10:54 AM
Dynamic Wrapper Tutorial
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
And for my 1000th post I will perform the following trick: Just kidding, I will explain how to use the Dynamic Wrapper.
The Dynamic Wrapper (or DynaWrap/DynaCall) allows you to call Win32 API's. This is something most scripting languages do not support, apart from AutoIT. In an effort to enable the quicklaunch bar I stumbled upon this (not wanting to trade KiX in for AutoIT).
To understand how this works in essence is to understand programming languages a bit more. Normally only programming languages are able to directly call API's, in a difficult manor.
Most things you will want to use are Windows, since we are working in Windows. Every window or Item has a handle. Most of them are pre-defined but if you don't know the handle you can find one (explained later). a handle is is called hWnd in programming languages the H in hWnd stands for handle, the WND stands for Window. so in order to manipulate a window, for instance the QuickLaunch bar you first have to find the tray handle.
This is where the FindWindow API comes in (which is included in User32.dll). Microsoft does good attempt at describing this function at http://msdn.microsoft.com/en-us/library/ms633499(VS.85).aspx You'll see that the hWnd of FindWindow needs 2 Data strings.
LPCTSTR, these are string values, thats the simple explanation. LPCTSTR stands for Long Pointer ConsTant STRing Actually they are Const Char* variables. This means a variable of the type Char that cannot be changed as the "Const" dictates. [history] Char comes from the early programming days and was the predesessor of the String type. Although alot of ppl can correct me here I like to believe it was the adam (char) to the eve (int). Int as we all know is Integer which contains numbers, char would contain letters. Evolution had us see more Int types, Int32, Long, Double, Float and so on. In a lesser degree then Int, Char also evolved into Char[lenght] Char* and eventually a new type "String". [/history] Const is also used in VBS in which you declare a variable that can not be altered lateron. LPCTSTR also casts the type "String".
Moving on now, so we need to including this Data Type 2 times. Let's look at the Readme included with DynaWrap
i=describes the number and data type of the functions parameters {'s', sizeof(BSTR), VT_LPSTR}, // s string
This means that if we use FindWindow we have to use i and since we have 2 string types the end result will be i=ss. Two times s because as MS dictates 2 LPCTSTR's are used.
Keeping in the readme, since we are using a windows compiled DLL (user32.dll), we already know that F is going to be.
f=type of call _stdcall or _cdecl. So it can work with both MS C++ and Borland C++. Default to _stdcall. If that doesn't work use _cdecl. If that doesn't work good luck!
So in effect f=s.
Last but not least is R.
Since the handle returned is a number, you would expect Int being used. However Long is preferred since it's C. I can't really explain it but in Windows API's it's the preferred choice. so r=l.
So knowing all of the above we can start by writing our first KiX code.
Dim $objDynaWrap
$objDynaWrap = CreateObject("DynamicWrapper")
$=objDynaWrap.Register("USER32.DLL", "FindWindow", "i=ss", "f=s", "r=l")
So now we have created the Object and Register that we are going to use FindWindow and that the wrapper (and us) should use the parameters that we provided. Now we have to actually USE FindWindow and tell FindWindow what to find. We know from MS that we have to Provide FindWindow with 2 parameters, the Class Name and the Window Name. Now it gets a bit difficult to explain but you'll have to trust me on this when I tell you we are looking for "Shell_TrayWnd", this can be found in the windows.h (header for windows API's in the C\C++ language). And since the tray doesn't have a windows name the code will be this:
$lhWnd = $objDynaWrap.FindWindow("Shell_TrayWnd", "")
You'll notice that I've called the variable that will contain the handle $lhWnd. This is done by my own preference and to let it show that it is a Windows Handle of the type long. (off course in Kix it'll be returned as Int).
So the final code would look like this:
Dim $objDynaWrap, $lhWnd
$objDynaWrap = CreateObject("DynamicWrapper")
$=objDynaWrap.Register("USER32.DLL", "FindWindow", "i=ss", "f=s", "r=l")
$lhWnd = $objDynaWrap.FindWindow("Shell_TrayWnd", "")
? $lhWnd
And this concludes our lesson for today, I hope you understand my ramblings. Next lesson will show what to do with the handle and how to use it. This lessen was to teach what everything means in the Dynamic Wrapper and how it is used.
Here is Lesson 2!!
Edited by apronk (2008-10-03 05:12 PM) Edit Reason: Linked Lesson 2
|
Top
|
|
|
|
#189988 - 2008-10-02 01:20 PM
Re: Dynamic Wrapper Tutorial
[Re: Arend_]
|
BradV
Seasoned Scripter
Registered: 2006-08-16
Posts: 686
Loc: Maryland, USA
|
Very nice!
In 7 bit ASCII, each character is a single byte. If you put multiple characters together, you created a string. A single character was something that could easily fit into an 8 bit processor's register. Multiple characters couldn't.
Brad
|
Top
|
|
|
|
#189989 - 2008-10-02 02:22 PM
Re: Dynamic Wrapper Tutorial
[Re: BradV]
|
Benny69
Moderator
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
Well Done! and Congrats on the Prestigious post count.
|
Top
|
|
|
|
#207212 - 2013-04-26 09:53 PM
Re: Dynamic Wrapper Tutorial
[Re: NTDOC]
|
Allen
KiX Supporter
Registered: 2003-04-19
Posts: 4549
Loc: USA
|
Since the location of the Home page for Dynawrap seems to be very volatile, I thought I would post the dlls and the info that is currently on the home page so that we will have a copy here. This is the kind of stuff that get's lost way to easily.
As of 2013/04/26 the home page is here: http://www.borncity.com/web/WSHBazaar1/WSHDynaCall.htm
Attachments
dynawrapNt.zip (1524 downloads) Description:
dynawrap95.zip (1644 downloads) Description:
webpage.txt (1520 downloads) Description:
|
Top
|
|
|
|
#207216 - 2013-04-27 01:24 PM
Re: Dynamic Wrapper Tutorial
[Re: Allen]
|
Arend_
MM club member
Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
|
Thanks Allen, I did update the links in my latest UDF, but didn't think of updating it here as well
|
Top
|
|
|
|
#212108 - 2016-11-15 10:09 AM
Re: Dynamic Wrapper Tutorial
[Re: Arend_]
|
Seaman
Just in Town
Registered: 2016-11-15
Posts: 1
Loc: Germany
|
Since couple weeks the McAffee Virusscan detects in the dynamicwrapperx.dll v.2.1.1.1 ( a product of the russian guy called Yuri Popov ) RDN/Ransom trojan. It appears to be so called one of lots of improvements
|
Top
|
|
|
|
#213503 - 2018-07-05 09:33 PM
Re: Dynamic Wrapper Tutorial
[Re: Arend_]
|
AndreLuiz
Getting the hang of it
Registered: 2015-10-07
Posts: 89
Loc: Brasil, João pessoa
|
[PtBr] Olá, é possível registrar ".dll" comum, sem ser "COM DLL"?
[ENG] Hello, Is it possible to register "common .dll" without being "COM DLL"?
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 370 anonymous users online.
|
|
|