Page 1 of 1 1
Topic Options
#189985 - 2008-10-02 10:54 AM Dynamic Wrapper Tutorial
Arend_ Moderator Offline
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
 Quote:

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.
 Quote:

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.
 Quote:

r=return data type.


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.
 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:
 Code:
$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:
 Code:
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 Offline
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 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
Well Done! and Congrats on the Prestigious post count.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#189997 - 2008-10-02 04:28 PM Re: Dynamic Wrapper Tutorial [Re: Benny69]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Sweet! Dude... I'm so glossed over right now. I got some investigating to do if I really want to understand all this. Thanks.
Top
#190004 - 2008-10-02 09:48 PM Re: Dynamic Wrapper Tutorial [Re: Arend_]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11624
Loc: CA
Thanks for the research and posting of your findings, good find.
Top
#207212 - 2013-04-26 09:53 PM Re: Dynamic Wrapper Tutorial [Re: NTDOC]
Allen Administrator Offline
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_ Moderator Offline
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
#209461 - 2014-09-27 04:17 PM Re: Dynamic Wrapper Tutorial [Re: Rinzwind]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4549
Loc: USA
Awesome. Thanks for posting the info.
Top
#209483 - 2014-10-03 09:43 AM Re: Dynamic Wrapper Tutorial [Re: Allen]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Thanks for that!
Top
#212108 - 2016-11-15 10:09 AM Re: Dynamic Wrapper Tutorial [Re: Arend_]
Seaman Offline
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
#212109 - 2016-11-15 01:10 PM Re: Dynamic Wrapper Tutorial [Re: Seaman]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1895
Loc: Hilversum, The Netherlands
Thanks for the info, I'll delete the post of the Russion version.
Top
#213503 - 2018-07-05 09:33 PM Re: Dynamic Wrapper Tutorial [Re: Arend_]
AndreLuiz Offline
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
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 370 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.078 seconds in which 0.031 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org