找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 5581|回复: 10

[飞鸟集] DynamicWrapperX的最新版本和特点

[复制链接]

已领礼包: 8121个

财富等级: 富甲天下

发表于 2013-11-1 10:52:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
本帖最后由 Highflybird 于 2013-11-1 11:25 编辑

以前我在
http://bbs.xdcad.net/thread-667848-1-1.html

http://bbs.xdcad.net/thread-667890-1-1.html

这两篇帖子里面谈到了DynamicWrapperX的应用。它具有强大的功能。而在当时,它只是能用在32的CAD上。
现在这个版本升级到2.0版本了,能适用于64位的系统和CAD,而且变得更加强大了。
这个版本的新的特性如下:
1.能完全兼容64位系统。

2.可以直接在函数中嵌入代码(特别是汇编语言代码)。

3.一些新的函数和版本查询帮助。

4.增加了内存分配释放函数。

5.可以获取变量或者一个对象的实例。

6.可以从内存地址获取函数。

我这里附上这个插件的最新版本和帮助文件。

Dynwrapx2.0.0.0.zip

44.94 KB, 下载次数: 250, 下载积分: D豆 -1 , 活跃度 1

评分

参与人数 1威望 +1 D豆 +5 贡献 +1 收起 理由
xshrimp + 1 + 5 + 1 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!

已领礼包: 8121个

财富等级: 富甲天下

 楼主| 发表于 2013-11-1 10:56:29 | 显示全部楼层
Author: Yuri Popov
License: freeware
ContentsIntroduction
DynamicWrapperX is an ActiveX component (COM server) inspired by DynamicWrapper, which I wrote as an attempt to better implement the idea. With it you can register functions exported by DLL libraries, in particular Windows API functions, as object methods and then call them from scripts written in JScript, VBScript, or similar scripting languages. Starting with version 2, you can also register a function using its address in memory or its machine code represented in the form of a hex string. This component is not a modification of the original DynamicWrapper, it was written from scratch in the GoAsm assembly language. Version 2 has been tested under Windows XP SP3, Windows 7 SP1, and Windows 8.1.
New features of version 1 as compared with DynamicWrapper:
  • Registration for the current user. This can be useful if the user does not have administrator privileges.
  • An expanded set of input parameter and return value types.
  • Output parameters.
  • Unified the way strings are passed in JScript and VBScript.
  • Added callback, which enables API functions to call script functions. This is necessary for using APIs such as EnumWindows (see examples below).
  • On Windows 98 it is no longer necessary to create a separate object instance for each registered function.
  • Several useful built-in methods: NumGet, NumPut, StrPtr, StrGet, Space.
Changes in version 2:
  • Windows 98 is not officially supported (I have not tested version 2 on it).
  • The component is now available in two variants: x86 and x64.
  • Its CLSID has been changed.
  • During registration a check is made to see if version 1 is registered. What follows depends on the result of the check (see Registration in the system below).
  • New parameter and return value types: m (Int64), q (UInt64), v (a pointer to a VARIANT structure).
  • The number of callback functions is unlimited.
  • The Register method is now capable of registering a function by its ordinal or under a different name. The flag parameter (f=...) is useful again.
  • New built-in methods: RegisterAddr, RegisterCode, StrPut, ObjPtr, ObjGet, ArrPtr, VarPtr, MemAlloc, MemFree, Bitness, Version.
  • For the StrPtr, StrGet, and StrPut methods you can specify the string's codepage instead of its type.
---------------------------------------------------------------------------
P.S. Though I have tried to test DynamicWrapperX in various situations, I cannot guarantee its faultless work. Use it at your own risk.
Registration in the system
Register the component in one of these two ways:
regsvr32.exe path-to-the-component\dynwrapx.dll — for all users.
regsvr32.exe /i path-to-the-component\dynwrapx.dll — for the current user.
If dynwrapx.dll is located in the System32, System, Windows directory, the current directory or one of those listed in the PATH environment variable, the path is optional. After registering dynwrapx.dll for the current user, the DynamicWrapperX object will only be available to this user. Besides, under Windows Vista, Windows 7, and Windows 8 it will be unavailable to applications running with administrator rights.
On a 64-bit system both variants, x86 and x64, should be registered so that both 32-bit and 64-bit applications can use the component.
In the process of registration, version 2 will check whether version 1 is already registered. If so, version 2 will be installed in parallel with version 1 and will be available in scripts only by its version-dependent name DynamicWrapperX.2. To replace version 1 with version 2, you have to unregister it first. In this case version 2 will also be available by its generic name DynamicWrapperX.
Unregister the component as follows:
regsvr32.exe /u path-to-the-component\dynwrapx.dll — for all users.
regsvr32.exe /u /i path-to-the-component\dynwrapx.dll — for the current user.
If version 1 is also installed, unregistering version 2 will leave its registration intact (and vice versa).
Built-in methods(click the number for a more detailed description)
[1]  Register( DllName, FuncName [, i=ParamTypes] [, r=RetValType] [, f=Flags] ) — registers a function from a DLL as an object method.
[2]  RegisterAddr( Addr, FuncName, [, i=ParamTypes] [, r=RetValType] [, f=Flags] ) — registers a function by its address in memory.
[3]  RegisterCode( HexStr [, FuncName] [, i=ParamTypes] [, r=RetValType] [, f=Flags] ) — registers the machine code of a function represented in the form of a hex string.
[4]  RegisterCallback( FuncRef [, i=ParamTypes] [, r=RetValType] ) — registers a script function as a callback function.
[5]  NumGet( Address [, Offset] [, Type] ) — reads a number from memory.
[6]  NumPut( Var, Address [, Offset] [, Type] ) — writes a number to memory.
[7]  StrPtr( Var [, Type/Codepage] ) — returns a pointer to a string.
[8]  StrGet( Address [, Type/Codepage] ) — reads the string at the specified address.
[9]  StrPut( Str, Address [, Type/Codepage] ) — writes a string to memory at the specified address.
[10]  Space( Count [, Char] ) — creates a string of the specified length.
[11]  ObjPtr( Object ) — returns a poiter to an object.
[12]  ObjGet( ObjPtr ) — retrieves an object by its pointer.
[13]  ArrPtr( Array ) — returns a pointer to the SAFEARRAY structure of the specified array.
[14]  VarPtr( Variable ) — returns a pointer to the VARIANT structure of a script variable.
[15]  MemAlloc( Bytes [, ZeroMem] ) — allocates memory.
[16]  MemFree( MemPtr ) — frees memory.
[17]  Bitness() — returns the bitness (32 or 64) of the DynamicWrapperX object.
[18]  Version( [Field] ) — returns the specified field(s) of the four-part version number of DynamicWrapperX.
Register method
This method registers a function exported by the specified DLL as an object method. After that you can call the function in the same way as the built-in methods, i.e. by its name after a point. The 1st parameter is the name of the DLL, the 2nd is the name of the function. The other three parameters may or may not be present, depending of the function, and their order is arbitrary because they are distinguished by their prefixes. The i= prefix denotes the types of the function's parameters, r= specifies the type of the return value, and f= sets flags that affect the way the function is called.
JScript
DWX = new ActiveXObject("DynamicWrapperX");                  // Create an object instance.DWX.Register("user32.dll", "MessageBoxW", "i=hwwu", "r=l");  // Register a dll function.res = DWX.MessageBoxW(0, "Hello, world!", "Test", 4);        // Call the function.
VBScript
Set DWX = CreateObject("DynamicWrapperX")                    ' Create an object instance.DWX.Register "user32.dll", "MessageBoxW", "i=hwwu", "r=l"    ' Register a dll function.res = DWX.MessageBoxW(0, "Hello, world!", "Test", 4)         ' Call the function.
The library name without a path causes searching by name. The search starts with the libraries already loaded for the process and continues on disk. Here is the default disk search order under Windows XP:
  • The application's directory (in this case the application is either wscript.exe or cscript.exe).
  • The current directory.
  • System32.
  • System.
  • Windows.
  • The directories listed in the PATH environment variable.
If the library resides in a file with a ".dll" extension, the extension is optional, i.e. in the above example we could have written just "user32". If the file that contains the library has no extension, you should put a point after the name. For example, "mylib."
If the function is registered by its ordinal, the number is placed after the library name and separated from it with a colon. The same applies to registration under a different name. The latter may be useful if the function's name contains characters illegal for method names.
Remember that ordinal numbers are not guaranteed to be the same across different versions of a DLL and between the x86 and x64 variants of the same version.
The ordinal number can be decimal or hexadecimal with a "0x" prefix. If the library name has no extension, ".dll" is assumed.
JScript
DWX.Register("user32:110", "MethodName", "i=hwwu", "r=l");  // Register by ordinal.DWX.Register("user32:BadName", "GoodName", "i=hwwu", "r=l"; // Register under a different name.
VBScript
DWX.Register "user32:110", "MethodName", "i=hwwu", "r=l"   ' Register by ordinal.DWX.Register "user32:BadName", "GoodName", "i=hwwu", "r=l" ' Register under a different name.
The function name in Windows API may vary depending on whether you need the Unicode version of a function or its ANSI counterpart. This normally applies only to the functions having string parameters or return values. For example, the function named MessageBox in Windows API documentation actually exists in two variants: MessageBoxW (for Unicode strings) and MessageBoxA (for ANSI ones). I left the traditional search logic unchanged. That is, if you specified MessageBox and such a function has not been found in user32.dll, the search will be automatically repeated for MessageBoxA. The names of Unicode functions should be specified accurately, with a 'W' at the end of them.
The parameter list can be omitted only if the function takes no parameters (by design).
The return value can be omitted whenever you don't need it, regardless of whether the function returns any value or not.
JScript
DWX = new ActiveXObject("DynamicWrapperX");DWX.Register("kernel32", "GetCommandLine", "r=s");      // This function has no parameters.CmdLine = DWX.GetCommandLine();                         // The command that started the process.WScript.Echo(CmdLine);
VBScript
Set DWX = CreateObject("DynamicWrapperX")DWX.Register "kernel32", "Beep", "i=uu"      ' Beep returns a value but it is not needed.DWX.Beep 800, 1000                           ' A sound through the PC speaker (beeper).
The flag parameter currently has only one possible value "t" meaning the function's calling convention is "thiscall". It is only used by the 32-bit version of DynamicWrapperX and is ignored by the 64-bit one.
JScript
DWX.Register("SomeLib", "SomeFunc", "i=hwwu", "r=l", "f=t");  // Use thiscall when calling the function.
VBScript
DWX.Register "SomeLib", "SomeFunc", "i=hwwu", "r=l", "f=t"  ' Use thiscall when calling the function.RegisterAddr method
This method registers a function by its memory address. The other parameters are the same as those of Register.
JScript
DWX.RegisterAddr(Address, "FuncName", "i=hwwu", "r=l");
VBScript
DWX.RegisterAddr Address, "FuncName", "i=hwwu", "r=l"RegisterCode method
The 1st parameter of this method takes the machine code of a function in the form of a hex string. Memory is allocated and the code is written to it in binary form. After that, you can call it by the name specified in the 2nd parameter. The method returns the address of the code. Machine code is different for x86 and x64, hence the need to check the bitness of the process (via checking the DynamicWrapperX object's bitness) to figure out which version of the code to use. One possible application for machine code functions is processing large amounts of data, where machine code may run tens or even hundreds of times faster than script code.
If you want to use the code by its address, without creating a new method, you can omit all arguments except the 1st one. But keep in mind that the memory allocated for the code is still connected with the object and will be freed if the object is released.
The hex string can be continuous or divided into parts by spaces, tabs, or newlines.
JScript
DWX = new ActiveXObject("DynamicWrapperX");if (DWX.Bitness == 32) {    Code = "8B442404F76C2408C3"  // The function multiplies its arguments and returns the result.}else {    Code = "4889C8 48F7EA C3"    // mov rax,rcx; imul rdx; ret}CodeAddr = DWX.RegisterCode(Code, "Multiply", "i=ll", "r=l");WScript.Echo(DWX.Multiply(5, 4));
VBScript
Set DWX = CreateObject("DynamicWrapperX")If DWX.Bitness = 32 Then    Code = "8B442404F76C2408C3"  ' The function multiplies its arguments and returns the result.Else    Code = "4889C8 48F7EA C3"    ' mov rax,rcx; imul rdx; retEnd IfCodeAddr = DWX.RegisterCode(Code, "Multiply", "i=ll", "r=l")WScript.Echo(DWX.Multiply(5, 4))
You can also insert comments right in the hex string, surrounding them with parentheses.
Code = "4889C8 (mov rax,rcx) 48F7EA (imul rdx) C3 (ret)"If the hex string is multiline, you can mark comments with a semicolon.
JScript
Code = "4889C8  ; mov rax,rcx \n" +       "48F7EA  ; imul rdx \n" +       "C3      ; ret"VBScriptCode = "4889C8  ; mov rax,rcx" & vbCrLf & _       "48F7EA  ; imul rdx" & vbCrLf & _       "C3      ; ret"
But note that in this case each line (except the last one) must have a newline character or characters at the end because they are used as the end-of-comment marker.
Types of input parameters and return values
m — signed 64-bit integer — INT64, LONGLONG, ...
q — unsigned 64-bit integer — UINT64, ULONGLONG, ...
l — signed 32-bit integer — LONG, INT, LRESULT, BOOL, ...
u — unsigned 32-bit integer — ULONG, UINT, DWORD, ...
h — handle — HANDLE, HWND, HMODULE, HINSTANCE, HICON, ... — 32-bit (x86) or 64-bit (x64) integer.
p — pointer; for numbers it is the same as u (x86) or q (x64) but can also be used to pass an object (IDispatch *) or a string.
n — signed 16-bit integer — SHORT
t — unsigned 16-bit integer — USHORT, WORD, WCHAR, OLECHAR, ...
c — signed 8-bit integer — CHAR
b — unsigned 8-bit integer — UCHAR, BYTE, ...
f — single-precision floating-point number (32 bits) — FLOAT
d — double-precision floating-point number (64 bits) — DOUBLE
w — Unicode string — BSTR, LPWSTR, LPOLESTR, OLECHAR *, WCHAR *, ...
s — ANSI/Windows string (default codepage) — LPSTR, LPCSTR, CHAR *, ...
z — OEM/DOS string (default codepage) — LPSTR, LPCSTR, CHAR *, ...
v — pointer to a VARIANT structure.
Besides handles and pointers, there are other types that change their bitness with the bitness of the process. For example: LPARAM, WPARAM, SIZE_T. They should also be passed and returned as type h or p so your code can work correctly regardless of the bitness of the script interpreter.
The script types corresponding to m and q would be VT_I8 and VT_UI8, but they are not supported by JScript and VBScript, which limits what you can do with 64-bit integers in scripts. As long as the value returned by the function allows this, DynamicWrapperX converts it to type VT_I4 (32-bit signed integer) or VT_R8 (double-precision floating-point number). Since the mantissa of VT_R8 has only 53 bits, it cannot represent every number in the range of the 64-bit integer. In that case VT_I8 or VT_UI8 is returned. All you can do with these types is pass them as arguments to some other method or display their values via WScript.Echo or MsgBox. No calculations are possible.
When a large integer is returned as VT_R8 and you want to see its value in a message box, it may not be displayed correctly because the number of digits after the decimal point in string representation of a floating-point number is limited. So if, for example, the number is 9223372036854775808, in the message box you may see 9,22337203685478E+18 instead of 9,223372036854775808E+18. However, the actual numeric value in the variable is not rounded and remains accurate.
If the value of a 64-bit integer does not fit in any numeric type available, you can specify it in string format, decimal or hexadecimal (with a 0x prefix).
DWX.Register("lib.dll", "func", "i=m")DWX.func("0xFFFFFFFFFFFFFFFF")DWX.func("-0x7FFFFFFFFFFFFFFF")DWX.func("18446744073709551615")DWX.func("-9223372036854775807")Output parameters
M — pointer to the specified number (its address in memory) — LONGLONG *, PLONGLONG, ...
Q — same as above — ULONGLONG *, PULONGLONG, ...
L — same as above — LONG *, LPLONG, ...
H — same as above — HANDLE *, PHANDLE, LPHANDLE, ...
U — same as above — ULONG *, LPDWORD, ...
P — same as above
N — same as above — SHORT *
T — same as above — USHORT *, LPWORD, WCHAR *, OLECHAR *, ...
C — same as above — CHAR *, ...
B — same as above — UCHAR *, LPBYTE, ...
F — same as above — FLOAT *, PFLOAT
D — same as above — DOUBLE *, PDOUBLE
W — output Unicode string
S — output ANSI string
Z — output OEM string
The output types above can be used in scripting languages that pass arguments to methods by reference as VBScript does. In that case DynamicWrapperX can obtain a pointer to the argument's value, which it then passes to the registered function so the function can change the value at that address. If arguments are passed by value, like in JScript, they are copied, so there is no way to find and change the original. In this case you can allocate a buffer in memory by means of MemAlloc, give the returned pointer to the function (as the p type) and after calling the function read the number it put in the buffer with NumGet.
Some scripting engines also copy strings before passing them to methods, in which case the use of output types for strings makes no sense either. The solution to this is similar to the above: a memory buffer passed as type p and reading the resulting string from it via StrGet.
Strings
Strings in JScript and VBScript are of the BSTR type. These are Unicode strings, i.e. the code of each character takes 2 bytes. The last character is followed by a terminator (two zero bytes), and the first character is preceded by a 4-byte number that contains the length of the string in bytes (excluding zero bytes at the end of the string). A script string variable holds a pointer to such a string, which is the address of the string's first character (i.e. the bytes that contain the string length remain "behind-the-scenes").
To pass a string you have the following three ways:
1) An input string: w, s, z. Strings passed as s or z are copied and converted into the relevant encoding. The API function receives a pointer to such a copy. As soon as the function returns, the memory used for the copy is released. In the case of w the function receives a pointer to the original (Unicode) string.
2) An output string: W, S, Z. Here with all three types you pass a pointer to the original location of the string. S and Z strings are previously converted into the relevant encoding but without copying. When the function returns, the contents of S and Z strings are converted back into Unicode and their length is measured. W strings only have their length measured. The length (in bytes) is recorded in front of the string. The last operation is needed to avoid glitches while, for example, this and other strings will be concatenated further in the script. Since the output string, like all output parameters, is intended to be written to by the called function, make sure its length is sufficient.
3) A pointer: p. This is the simplest way. Here you pass a pointer to the original string, without conversion. After the function returns, no conversion or length correction is made. So if the function has written something to this string, that data will remain there unchanged.
This might look the same as w, but there is a difference. Parameters declared as p accept not only string variables but also numeric ones.
Returning a string as p, we get a numeric variable holding a pointer to the string returned by the API function. Returning a string as w, s or z, we get a string variable holding a pointer to a copy of the string returned by the API function. Strings returned as s and z are copied with conversion. The original strings are not freed. This is because DynamicWrapperX has no idea how memory for the string was allocated. If you are concerned about memory leak caused by that, consider using the p type for strings returned by API functions wherever possible.
API functions that take string arguments typically exist in two variants — for example, MessageBoxA and MessageBoxW. It appears more reasonable in scripts to use the Unicode versions (those having a 'W' at the end of the name) because this way you avoid conversion to and from Unicode.
Use of strings as memory buffers may or may not be a reliable technique depending on how the script engine treats strings internally. So I recommend using MemAlloc instead of Space for that purpose.
RegisterCallback method
This method takes a reference to a script function and transforms it into a pointer that can be passed to an API function. Then that API function can use this pointer to call the script function. EnumWindows, for example, requires such a pointer to a callback procedure for its work. For each window that it finds, it calls the callback procedure, passing it the window handle. Then if the callback procedure returns 1, enumeration continues, and if 0, it stops.
A script function reference by itself cannot serve this purpose because functions in JScript and VBScript are objects and their references are pointers to IDispatch interfaces. So the reference is passed to RegisterCallback, and the API function receives a pointer to one of the intermediary procedures inside dynwrapx.dll, which will translate calls to the script function and transfer its return values back to the API function.
In JScript the name of a function (without parentheses) will serve as its reference, and in VBScript you will have to use GetRef beforehand. In addition to the function's reference, you may have to specify the types of its parameters (if any) and its return value — just as with the Register method (but only small letters can be used).
JScript
DWX = new ActiveXObject("DynamicWrapperX");DWX.Register("user32", "EnumWindows",    "i=ph");DWX.Register("user32", "GetWindowTextW", "i=hpl");          // Unicode variant.// DWX.Register("user32", "GetWindowText", "i=hpl");        // ANSI variant.pCbkFunc = DWX.RegisterCallback(CbkEnumWin, "i=hh", "r=l"); // Register CbkEnumWin                                                            // as a callback procedure                                                            // and get its pointer.n=0, m=0, WinList="";Buf = DWX.MemAlloc(256);             // Buffer for the window titles (an output string).DWX.EnumWindows(pCbkFunc, 0);        // Call EnumWindows and pass it the pointer                                     // to the callback procedure.DWX.MemFree(Buf);WScript.Echo("Windows in total: " + m + "\nWith a title: " + n + "\n\n" + WinList);// ............... The callback function itself ....................function CbkEnumWin(hwnd, lparam){    var Title;    DWX.GetWindowTextW(hwnd, Buf, 128);     // Unicode    Title = DWX.StrGet(Buf, "w");    //DWX.GetWindowText(hwnd, Buf, 256);    // ANSI    //Title = DWX.StrGet(Buf, "s");    if(Title.length > 0) {  // Add the title to the list if its length is greater than 0.        WinList += hwnd + "\t" + Title + "\n";        ++n;    }    ++m;    return 1;               // Returning 0 will stop the calls.}
VBScript
Set DWX = CreateObject("DynamicWrapperX")DWX.Register "user32", "EnumWindows",    "i=ph"DWX.Register "user32", "GetWindowTextW", "i=hpl"     ' Unicode variant.'DWX.Register "user32", "GetWindowText", "i=hpl"     ' ANSI variant.Set Ref = GetRef("CbkEnumWin")  ' Get a reference to the function.pCbkFunc = DWX.RegisterCallback(Ref, "i=hh", "r=l")  ' Register CbkEnumWin                                                     ' as a callback procedure                                                     ' and get its pointer.n = 0 : m = 0 : WinList = ""Buf = DWX.MemAlloc(256)        ' Buffer for the window titles (an output string).DWX.EnumWindows pCbkFunc, 0    ' Call EnumWindows and pass it the pointer                               ' to the callback procedure.DWX.MemFree BufWScript.Echo "Windows in total: " & m & vbCrLf & "With a title: " & n & _              vbCrLf & vbCrLf & WinList' ................ The callback function itself .......................Function CbkEnumWin(hwnd, lparam)    DWX.GetWindowTextW hwnd, Buf, 128   ' Unicode    Title = DWX.StrGet(Buf, "w")    'DWX.GetWindowText hwnd, Buf, 256   ' ANSI    'Title = DWX.StrGet(Buf, "s")    If Len(Title) > 0 Then  ' Add the title to the list if its length is greater than 0.        WinList = WinList & hwnd & vbTab & Title & vbCrLf        n = n+1    End If    m = m+1    CbkEnumWin = 1          ' Returning 0 will stop the calls.End FunctionOther methods
Note: parameters in brackets are optional, but you can't omit a parameter if the one following it is present.
NumGet( Address [, Offset] [, Type] ) — reads a number from memory. Address — a base address. Offset — a displacement (in bytes) from the base, positive or negative (0 by default): it can be used in loops for reading/writing sequences of numbers. Type — the type of the retrieved number ("l" by default). Only small letters can be used. The number is put in the value returned by the method.
NumPut( Var, Address [, Offset] [, Type] ) — writes a number to memory. Var — either a literal number or the name of a variable holding it. The rest is similar to NumGet. The return value of the method will be the address just after the last written byte.
With both methods above, Address can be either a number or a string, in the latter case the string pointer will serve as the base address. This allows to use strings as memory buffers for storing any data — structures, arrays, etc.
StrPtr( Var [, Type/Codepage] ) — returns a pointer to a string. Var — a string variable or constant. Type/Codepage — the type or encoding of the destination string. Can be: w (by default), s, z, or a codepage, e.g. "cp65001" (UTF-8) or "cp1201" (UTF-16 Big Endian). For s, z, or a codepage the string is previously converted in place. If the resulting string does not fit in the original string's buffer, it will be truncated. Since the original is in Unicode, where each character takes two bytes, there will be more than enough space in most cases. Maybe some East-Asian text can be longer in an ANSI or UTF-8 encoding than it is in UTF-16, but I am just guessing.
StrGet( Address [, Type/Codepage] ) — reads the string at the specified address. Returns a copy of the string. Address can be either a numeric variable or a string one. Type/Codepage — the type or encoding of the source string. For options see StrPtr.
StrPut( String, Address [, Type/Codepage] ) — writes a string to the specified address. Type/Codepage — the type or encoding of the destination string. For options see StrPtr. The method returns the address after the string's null terminator. If you set Address to 0, the method will return the size of the buffer required for the destination string, including the terminating null character.
Space( Count [, Char] ) — creates a string (BSTR) of the specified length. Returns a string variable. Count — the number of Unicode (two-byte) characters in the string. Char — a character to fill the string with. By default the string is filled with spaces, just as the Space function in VBScript does. To use nulls instead of spaces, specify Char as an empty string ("").
Note: This method was originally designed for creating strings that would serve as memory buffers — for numbers, structures, or output strings. However, practice has revealed that this technique is generally unsafe. You never know how the script engine will treat the memory allocated for a string; in other words, you do not have full control over it and your data stored in there may get lost or damaged. For this reason I recommend using MemAlloc to allocate memory (see below).
ObjPtr( Object ) — returns a pointer to an object.
ObjGet( ObjPtr ) — retrieves an object by a pointer to it. If the object supports the IDispatch interface, a VT_DISPATCH variable is returned, otherwise VT_UNKNOWN. The reference counter of the object is incremented.
ArrPtr( Array ) — returns a pointer to the SAFEARRAY structure of the specified array. Does not work for JScript arrays because they are actually objects.
VarPtr( Variable ) — in languages that pass variables to methods by reference, like VBScript, this method can retrieve a pointer to the VARIANT structure of the variable.
MemAlloc( Bytes [, ZeroMem] ) — allocates memory and returns a pointer to it. If the 2nd argument is 1, the memory will be filled with binary zeros.
MemFree( MemPtr ) — frees allocated memory.
Bitness() — retrieves the bitness of DynamicWrapperX (and thereby the bitness of the process that is using it). Returns number 32 or 64.
Version( [Field] ) — returns the specified field(s) of DynamicWrapperX's four-part version number. Set Field to the appropriate value according to the table below. If Field is omitted, it equals 0.
Suppose the full version is 2.5.7.10.
  0 — version string: "2.5.7.10"
  1 — major version number: 2
  2 — minor version number: 5
  3 — build number: 7
  4 — revision number: 10 (0xA)
  5 — major + minor number: 0x20005
  6 — build + revision number: 0x7000A
  7 — full version number: 0x200050007000A
As you can see, each field is a 16-bit integer and occupies two bytes.
Examples of usage
JScript
DWX = new ActiveXObject("DynamicWrapperX");str = "Hello, world! It's me.";// Reading from memory. Read the character codes of the string.codes = "";for(i=0; i < str.length; ++i)  codes += DWX.NumGet(str, i*2, "t") + " "; // i is multiplied by 2 because the offset                                            // must be in bytes and "t" is a two—byte type.WScript.Echo("Character codes:\n" + codes);// Reading from and writing to memory. The string is read and then written in reverse order.len = str.length;buf = DWX.MemAlloc(len * 2 + 2);        // Buffer for writing. Each Unicode char = 2 bytes.DWX.NumPut(0, buf, len * 2, "t");       // Put 2 zero bytes at the end (null terminator).for(i=0, j=len-1; i < len; ++i, --j) {  // len—1 is the index of the last character.  code = DWX.NumGet(str, i*2, "t");     // Read from left to right (the offset grows).  DWX.NumPut(code, buf, j*2, "t");      // Write from right to left (the offset decreases).}str1 = DWX.StrGet(buf);DWX.MemFree(buf);WScript.Echo("Reversed string:\n" + str1);// Manipulating strings.ptr = DWX.StrPtr(str);                  // Get a string pointer into a numeric                                        // variable, the string remains in Unicode.WScript.Echo("Address of the string: " + ptr);ptr = DWX.StrPtr(str, "z");             // Get a pointer to the same string                                        // previously converted to OEM/DOS.str1 = DWX.StrGet(ptr, "z");            // Read that string with                                        // conversion back to Unicode.WScript.Echo("Restored string:\n" + str1);// Create a UTF-8 copy of the string.bufsize = DWX.StrPut(str1, 0, "cp65001");buf = DWX.MemAlloc(bufsize);DWX.StrPut(str1, buf, "cp65001");// Read it back into Unicode.str2 = DWX.StrGet(buf, "cp65001");DWX.MemFree(buf);WScript.Echo("Converted from UTF-8:\n" + str2);
VBScript
Set DWX = CreateObject("DynamicWrapperX")str = "Hello, world! It's me."' Reading from memory. Read the character codes of the string.strlen = Len(str)codes = ""For i=0 To strlen-1  codes = codes & DWX.NumGet(str, i*2, "t") & " "  ' i is multiplied by 2 because the offset mustNext                                               ' be in bytes and "t" is a two—byte type.WScript.Echo "Character codes:" & vbCrLf & codes' Reading from and writing to memory. The string is read and then written in reverse order.buf = DWX.MemAlloc(strlen * 2 + 2)  ' Buffer for writing. Each Unicode char = 2 bytes.DWX.NumPut 0, buf, strlen * 2, "t"  ' Put 2 zero bytes at the end (null terminator).j = strlen-1                        ' strlen-1 is the index of the last character.For i=0 To strlen-1  code = DWX.NumGet(str, i*2, "t")   ' Read from left to right (the offset grows).  DWX.NumPut code, buf, j*2, "t"     ' Write from right to left (the offset decreases).  j = j-1Nextstr1 = DWX.StrGet(buf)DWX.MemFree bufWScript.Echo "Reversed string:" & vbCrLf & str1' Manipulating strings.ptr = DWX.StrPtr(str)                 ' Get a string pointer into a numeric                                      ' variable, the string remains in Unicode.   WScript.Echo "Address of the string: " & ptrptr = DWX.StrPtr(str, "z")            ' Get a pointer to the same string                                      ' previously converted to OEM/DOS.str1 = DWX.StrGet(ptr, "z")           ' Read that string with conversion back to Unicode.WScript.Echo "Restored string:" & vbCrLf & str1' Create a UTF-8 copy of the string.bufsize = DWX.StrPut(str1, 0, "cp65001")buf = DWX.MemAlloc(bufsize)DWX.StrPut str1, buf, "cp65001"' Read it back into Unicode.str2 = DWX.StrGet(buf, "cp65001")DWX.MemFree bufWScript.Echo "Converted from UTF-8:" & vbCrLf & str2
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

发表于 2013-11-1 11:00:43 来自手机 | 显示全部楼层
好东西啊,第一个支持!:)
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

发表于 2013-11-1 11:32:03 | 显示全部楼层
支持,飞鸟大师出关了。
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 40个

财富等级: 招财进宝

发表于 2013-11-1 11:43:55 | 显示全部楼层
大师,能否给写几个具体的应用?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 604个

财富等级: 财运亨通

发表于 2013-11-1 12:36:50 | 显示全部楼层
是呀,有应用示例,我等才能照虎画猫呀!!
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1268个

财富等级: 财源广进

发表于 2013-11-1 13:25:13 来自手机 | 显示全部楼层
飞鸟大师是打通任督二脉了,也点拨点拨我等啊
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 685个

财富等级: 财运亨通

发表于 2013-11-2 16:30:30 | 显示全部楼层
各版主对高飞的评价这么高啊~~~~~~我等小辈只有看热闹了
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 343个

财富等级: 日进斗金

发表于 2013-11-2 18:09:08 来自手机 | 显示全部楼层
方便做一些中文说明让国人学习吗?
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 1个

财富等级: 恭喜发财

发表于 2020-4-21 17:28:50 | 显示全部楼层
谢谢楼主分享
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

已领礼包: 22个

财富等级: 恭喜发财

发表于 2021-7-18 03:51:09 | 显示全部楼层
N多年了,不知道这个是否还是最新版
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 13:51 , Processed in 0.527999 second(s), 56 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表