How to use DynamicWrapper?
;==========================================================================================================================================
;
; How to use DynamicWrapper "dynwrap.dll" in WinBatch scripts.
;
;==========================================================================================================================================
; Following examples demonstrate how to use the "dynwrap.dll" for accessing API functions from WinBatch script.
;
; The examples need to have the ActiveX "dynwrap.dll" installed and registered as a COM server.
;
; The "dynwrap.dll" is part of the zip package "dynawrapNt.zip".
; Download from there: http://freenet-homepage.de/gborn/WSHBazaar/WSHDynaCall.htm
;
; See also: A DynaCall() Function for Win32, http://www.ddj.com/dept/windows/184416502
; See also: An Automation Object for Dynamic DLL Calls, http://www.ddj.com/dept/windows/210200078
;
; Copy the "dynwrap.dll" to a folder of your wish and register it in the system.
; To register "dynwrap.dll", type at the commandline prompt: "regsvr32.exe dynwrap.dll"
;
; This script programmatically registers the DynamicWrapper DLL file, which is assumed to reside in the same folder as this script.
; Un-registering is not provided by the DLL, but programmtically realized within this script by removing the specific registry keys.
;
; (c)Detlev Dalitz.20100124.20100125.
;==========================================================================================================================================


; Locate DynamicWrapper DLL.
strFileDLL = "DYNWRAP.DLL"
If FileExist (DirScript () : strFileDLL) != 0 Then strFileDLL = DirScript () : strFileDLL
   Else strFileDLL = FileLocate (strFileDLL)
Terminate (strFileDLL == "", "Terminated.", "DYNWRAP.DLL not found.")

; Register DynamicWrapper.
intResult = DllCall (DirScript () : "DYNWRAP.DLL", long : "DllRegisterServer")
Terminate (intResult != 0, "Terminated.", "DYNWRAP.DLL not registered.")


; Create DynamicWrapper object.
objDW = ObjectCreate ("DynamicWrapper")

; Register MessageBox function call.
objDW.Register("USER32.DLL", "MessageBoxA", "f=s", "i=hssu", "r=l")

; Display register message.
objDW.MessageBoxA(DllHwnd(""), "DynamicWrapper is registered.", "DynamicWrapper", 0)


; Example 1.
; Note: Calling format is: Microsoft compatible, Standard call, _stdcall.

; objDW.Register("USER32.DLL", "MessageBoxA", "f=ms", "i=hssu", "r=l") ; Function call already registered.
objDW.Register("USER32.DLL", "MessageBoxW", "f=ms", "i=hwwu", "r=l") ; Register function call for the wide character version of the MessageBox.

intResult1 = objDW.MessageBoxA(ObjectType("NULL"), "MessageBox (ANSI)", "From DynaWrap Object 1", 3)          ; 6 = Yes.
intResult2 = objDW.MessageBoxA(ObjectType("NULL"), "MessageBox (ANSI)", "From DynaWrap Object 2", 3 | 256)    ; 7 = No.
intResult3 = objDW.MessageBoxW(ObjectType("NULL"), ChrStringToUnicode ("MessageBox (UNICODE)"), ChrStringToUnicode ("From DynaWrap Object 3"), 3 | 512) ; 2 = Cancel.


; Example 2.
; Note: Calling format is: Microsoft C call, _cdecl, 8 byte real value.

; Register some functions from the Microsoft C Run-Time library.
objDW.Register("MSVCRT.DLL", "sin", "f=mc8", "i=d", "r=d")
objDW.Register("MSVCRT.DLL", "cos", "f=mc8", "i=d", "r=d")
objDW.Register("MSVCRT.DLL", "sinh", "f=mc8", "i=d", "r=d")
objDW.Register("MSVCRT.DLL", "cosh", "f=mc8", "i=d", "r=d")

Decimals (6)
fltResult1 = objDW.Sin(@PI / 2.0)  ; 1.000000
intResult1 = objDW.MessageBoxA(DllHwnd(""), : "Sin (@PI / 2.0) = " : fltResult1, "MSVCRT|Sin", 1 | 4096)

fltResult2 = objDW.SinH(@PI / 2.0) ; 2.301299
intResult2 = objDW.MessageBoxA(DllHwnd(""), : "SinH (@PI / 2.0) = " : fltResult2, "MSVCRT|SinH", 1 | 48)

fltResult3 = objDW.Cos(@PI / 2.0)  ; 0.000000
intResult3 = objDW.MessageBoxA(DllHwnd(""), : "Cos (@PI / 2.0)  = " : fltResult3, "MSVCRT|Cos", 1 | 64)

fltResult4 = objDW.CosH(@PI / 2.0) ; 2.509178
intResult4 = objDW.MessageBoxA(DllHwnd(""), : "CosH (@PI / 2.0) = " : fltResult4, "MSVCRT|CosH", 1 | 16)


; Example 3.
; Note: Calling format is: Microsoft compatible, Standard call, _stdcall.

objDW.Register("KERNEL32.DLL", "GetPrivateProfileString", "f=ms", "i=ssslls", "r=l")
;   DWORD WINAPI GetPrivateProfileString(
;     __in   LPCTSTR lpAppName,
;     __in   LPCTSTR lpKeyName,
;     __in   LPCTSTR lpDefault,
;     __out  LPTSTR lpReturnedString,
;     __in   DWORD nSize,
;     __in   LPCTSTR lpFileName
;   );

strIniFilename = DirHome () : "WIL.CLR"
strIniSection = "COLORS"
strIniKey = "CON"

intBBSize = 2048
hdlBB = BinaryAlloc (intBBSize)
BinaryEodSet (hdlBB, intBBSize)
intBBAddr = BinaryBufInfo (hdlBB, 1)
intSize = objDW.GetPrivateProfileString(strIniSection, strIniKey, "", intBBAddr, intBBSize, strIniFilename)
strIniValue = BinaryPeekStr (hdlBB, 0, intSize) ; e. g. "128,0,128"
hdlBB = BinaryFree (hdlBB)

objDW.MessageBoxA(DllHwnd(""), : strIniFilename : @LF : @LF : strIniSection : "=" : strIniValue, "GetPrivateProfileString", 0 | 64)


:@CANCEL
; Un-register DynamicWrapper.
If RegExistKey (@REGMACHINE, "SOFTWARE\Classes\DynamicWrapper\CLSID")
   strCLSID = RegQueryValue (@REGMACHINE, "SOFTWARE\Classes\DynamicWrapper\CLSID[]")
   If strCLSID != ""
      If RegExistKey (@REGMACHINE, "SOFTWARE\Classes\CLSID\" : strCLSID : "\InProcServer32")
         strFilePath = RegQueryValue (@REGMACHINE, "SOFTWARE\Classes\CLSID\" : strCLSID : "\InProcServer32[]")
         If FileExist (strFilePath) != 0
            If RegDeleteKey (@REGMACHINE, "SOFTWARE\Classes\DynamicWrapper")
               objDW.MessageBoxA(DllHwnd(""), : "Class entry deleted.", "DynamicWrapper", 0 | 64)
               If RegDeleteKey (@REGMACHINE, "SOFTWARE\Classes\CLSID\" : strCLSID)
                  objDW.MessageBoxA(DllHwnd(""), : "InProcServer32 deleted." : @LF : "Un-registering done.", "DynamicWrapper", 0 | 64)
               Else
                  objDW.MessageBoxA(DllHwnd(""), : "InProcServer32 not deleted." : @LF : "Check registry access rights.", "DynamicWrapper", 0 | 64)
               EndIf
            Else
               objDW.MessageBoxA(DllHwnd(""), : "Class not deleted." : @LF : "Check registry access rights.", "DynamicWrapper", 0 | 64)
            EndIf
         Else
            intResult = objDW.MessageBoxA(DllHwnd(""), : "Referenced DLL file not found at registered file path." : @LF : strFilePath : @LF : @LF : "Un-register anyway?", "DynamicWrapper", 4 | 32)
            If intResult == 6 ; IDYES.
               If RegDeleteKey (@REGMACHINE, "SOFTWARE\Classes\DynamicWrapper")
                  objDW.MessageBoxA(DllHwnd(""), : "Class entry deleted.", "DynamicWrapper", 0 | 64)
                  If RegDeleteKey (@REGMACHINE, "SOFTWARE\Classes\CLSID\" : strCLSID)
                     objDW.MessageBoxA(DllHwnd(""), : "InProcServer32 deleted." : @LF : "Un-registering done.", "DynamicWrapper", 0 | 64)
                  Else
                     objDW.MessageBoxA(DllHwnd(""), : "InProcServer32 not deleted." : @LF : "Check registry access rights.", "DynamicWrapper", 0 | 64)
                  EndIf
               Else
                  objDW.MessageBoxA(DllHwnd(""), : "Class not deleted." : @LF : "Check registry access rights.", "DynamicWrapper", 0 | 64)
               EndIf
            EndIf
         EndIf
      Else
         objDW.MessageBoxA(DllHwnd(""), : "InProcServer32 not found." : @LF : "Nothing to do.", "DynamicWrapper", 0 | 64)
      EndIf
   Else
      intResult = objDW.MessageBoxA(DllHwnd(""), : "CLSID key has no value." : @LF : "Delete key anyway?", "DynamicWrapper", 4 | 32)
      If intResult == 6
         blnResult = RegDeleteKey (@REGMACHINE, "SOFTWARE\Classes\DynamicWrapper")
         If blnResult Then objDW.MessageBoxA(DllHwnd(""), : "CLSID key deleted.", "DynamicWrapper", 0 | 64)
      EndIf
   EndIf
Else
   objDW.MessageBoxA(DllHwnd(""), : "Registry CLSID key not found." : @LF : "Nothing to do.", "DynamicWrapper", 0 | 64)
EndIf
Drop (objDW)
Exit
;==========================================================================================================================================