PureDispHelper UserLib - Update with Includefile for Unicode

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

If the one on pure area is not the correct one, I've got the .zip that was in the link from right before ts-soft's link quit working. If you want I can send it to you if its OK with ts-soft.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

SFSxOI wrote:If the one on pure area is not the correct one, I've got the .zip that was in the link from right before ts-soft's link quit working. If you want I can send it to you if its OK with ts-soft.
Please send it to André, thanks
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

sent...glad to help out.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2137
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

Thanks, SFSxOI for sending the email!

But: the download link posted above contains already the right (and latest) archive. So I've now corrected the download link in the Showcase project too and all is working fine... :D
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
nicolaus
Enthusiast
Enthusiast
Posts: 456
Joined: Tue Aug 05, 2003 11:30 pm
Contact:

Post by nicolaus »

@ts-soft
you have a example how i can create a excel file but how i can read a e exist excel file?

Where can i find informations for Methodes, Proberty´s and so, what the functions of the disphelper want as parameter?

thanks,
Nico
User avatar
mk-soft
Always Here
Always Here
Posts: 6201
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Post by mk-soft »

@nicolaus

Download from http://www.devcomponents.com/ COM Assistant.
It´s good tool. :wink:
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
flashvnn
New User
New User
Posts: 2
Joined: Mon Jun 23, 2008 4:21 pm

Post by flashvnn »

Hi, i see a Flash Example with puredisphelper, but how i use fscommand with puredisphelper.
please help
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

flashvnn wrote:Hi, i see a Flash Example with puredisphelper, but how i use fscommand with puredisphelper.
please help
Make a search for a vbs example and change it to puredisphelper (is easy)
I can't help, i have no documentation on this.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post by mback2k »

Would it be possible to create such lib for WMI classes? I need to be able to use SetDNSServerSearchOrder Method of the Win32_NetworkAdapterConfiguration Class and would like to avoid VBScript in my PureBasic program. Thanks in advance :) I am open for any advice in this issue.
http://msdn.microsoft.com/en-us/library ... S.85).aspx

I currently use this way, but I would like to directly access the WMI with PB.

Code: Select all

Interface IScriptControl Extends IDispatch
  get_Language(A)
  put_Language(strLanguage.p-bstr)
  get_State(A)
  put_State(A)
  put_SitehWnd(A)
  get_SitehWnd(A)
  get_Timeout(timeout)
  put_Timeout(timeout)
  get_AllowUI(A)
  put_AllowUI(A)
  get_UseSafeSubset(A)
  put_UseSafeSubset(A)
  get_Modules(A)
  get_Error(A)
  get_CodeObject(A)
  get_ProcedureDLLs(A)
  _AboutBox()
  AddObject(A,b,c)
  Reset()
  AddCode(source.p-bstr)
  Eval(A.p-bstr,*b.VARIANT)
  ExecuteStatement(A.p-bstr)
  Run(strCommand.p-bstr, intWindowStyle.l, bWaitOnReturn.l)
EndInterface

DataSection
  CLSID_ScriptControl:
  Data.l $0E59F1D5
  Data.w $1FBE,$11D0
  Data.b $8F,$F2,$00,$A0,$D1,$00,$38,$BC
  IID_IScriptControl:
  Data.l $0E59F1D3
  Data.w $1FBE,$11D0
  Data.b $8F,$F2,$00,$A0,$D1,$00,$38,$BC
EndDataSection

Procedure.s GetNameServer(ip$)
  Protected VBS$, ScriptControl.IScriptControl, var.VARIANT, result.s
  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_ScriptControl, 0, 1, ?IID_IScriptControl, @ScriptControl) = #S_OK
    ScriptControl\Reset()
    ScriptControl\put_Language("VBScript")
    VBS$ + "strComputer = " + Chr(34) + "." + Chr(34) + #CRLF$
    VBS$ + "Set objWMIService = GetObject(" + Chr(34) + "winmgmts:" + Chr(34) + " _" + #CRLF$
    VBS$ + "    & " + Chr(34) + "{impersonationLevel=impersonate}!\\" + Chr(34) + " & strComputer & " + Chr(34) + "\root\cimv2" + Chr(34) + ")" + #CRLF$
    VBS$ + "Set IPConfigSet = objWMIService.ExecQuery _" + #CRLF$
    VBS$ + "    (" + Chr(34) + "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE" + Chr(34) + ")" + #CRLF$
    VBS$ + "For Each IPConfig in IPConfigSet" + #CRLF$
    VBS$ + "    If IPConfig.IPAddress(0)=" + Chr(34) + ip$ + Chr(34) + " Then " + #CRLF$
    VBS$ + "        For i=LBound(IPConfig.DNSServerSearchOrder) to UBound(IPConfig.DNSServerSearchOrder)" + #CRLF$
    VBS$ + "            If i>0 Then" + #CRLF$
    VBS$ + "                name = name & " + Chr(34) + "," + Chr(34) + #CRLF$
    VBS$ + "            End If" + #CRLF$
    VBS$ + "            name = name & IPConfig.DNSServerSearchOrder(i)" + #CRLF$
    VBS$ + "        Next" + #CRLF$
    VBS$ + "    End If" + #CRLF$
    VBS$ + "Next" + #CRLF$
    ScriptControl\AddCode(VBS$)
    If ScriptControl\Eval("name", @var) = #S_OK
      Select var\vt
        Case #VT_BOOL
          If var\boolVal = #VARIANT_TRUE
            result = "1"
          Else
            result = ""
          EndIf
        Case #VT_BSTR
          result = PeekS(var\bstrVal, #PB_Any, #PB_Unicode)
        Case #VT_I1, #VT_UI1
          result = Str(var\bVal)
        Case #VT_I2, #VT_UI2
          result = Str(var\iVal)
        Case #VT_I4, #VT_UI4
          result = Str(var\lVal)
        Case #VT_I8, #VT_UI8
          result = StrQ(var\llVal)
        Case #VT_R4
          result = StrF(var\fltVal)
        Case #VT_R8
          result = StrD(var\dblVal)
        Default
          result = ""
      EndSelect
      VariantClear_(var)
    Else
      result = ""
    EndIf
    ProcedureReturn result
  EndIf
EndProcedure

Procedure.l SetNameServer(ip$, ServerList$)
  Protected VBS$, ScriptControl.IScriptControl, var.VARIANT, result.l
  CoInitialize_(0)
  If CoCreateInstance_(?CLSID_ScriptControl, 0, 1, ?IID_IScriptControl, @ScriptControl) = #S_OK
    ScriptControl\Reset()
    ScriptControl\put_Language("VBScript")
    VBS$ + "arrDNSServers = Array(" + Chr(34) + ReplaceString(ServerList$, ",", Chr(34) + "," + Chr(34)) + Chr(34) + ")" + #CRLF$
    VBS$ + "strComputer = " + Chr(34) + "." + Chr(34) + #CRLF$
    VBS$ + "Set objWMIService = GetObject(" + Chr(34) + "winmgmts:" + Chr(34) + " _" + #CRLF$
    VBS$ + "    & " + Chr(34) + "{impersonationLevel=impersonate}!\\" + Chr(34) + " & strComputer & " + Chr(34) + "\root\cimv2" + Chr(34) + ")" + #CRLF$
    VBS$ + "Set IPConfigSet = objWMIService.ExecQuery _" + #CRLF$
    VBS$ + "    (" + Chr(34) + "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE" + Chr(34) + ")" + #CRLF$
    VBS$ + "For Each IPConfig in IPConfigSet" + #CRLF$
    VBS$ + "    If IPConfig.IPAddress(0)=" + Chr(34) + ip$ + Chr(34) + " Then " + #CRLF$
    VBS$ + "        code = IPConfig.SetDNSServerSearchOrder(arrDNSServers)" + #CRLF$
    VBS$ + "    End If" + #CRLF$
    VBS$ + "Next" + #CRLF$
    ScriptControl\AddCode(VBS$)
    If ScriptControl\Eval("code", @var) = #S_OK
      Select var\vt
        Case #VT_BOOL
          If var\boolVal = #VARIANT_TRUE
            result = #True
          Else
            result = #False
          EndIf
        Case #VT_BSTR
          result = Val(PeekS(var\bstrVal, #PB_Any, #PB_Unicode))
        Case #VT_I1, #VT_UI1
          result = var\bVal
        Case #VT_I2, #VT_UI2
          result = var\iVal
        Case #VT_I4, #VT_UI4
          result = var\lVal
        Case #VT_I8, #VT_UI8
          result = var\llVal
        Case #VT_R4
          result = var\fltVal
        Case #VT_R8
          result = var\dblVal
        Default
          result = 0
      EndSelect
      VariantClear_(var)
    Else
      result = 0
    EndIf
    If Not result
      ProcedureReturn #True
    EndIf
  EndIf
  ProcedureReturn #False
EndProcedure
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

I second mback2k's suggestion for the disphelper having wmi, that would be great.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

http://disphelper.sourceforge.net/ wrote:Included with DispHelper are over 20 samples that demonstrate using COM objects including ADO, CDO, Outlook, Eudora, Excel, Word, Internet Explorer, MSHTML, PocketSoap, Word Perfect, MS Agent, SAPI, MSXML, WIA, dexplorer and WMI.
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
mback2k
Enthusiast
Enthusiast
Posts: 257
Joined: Sun Dec 02, 2007 12:11 pm
Location: Germany

Post by mback2k »

Thanks for the information. Could you convert the wmi.c as an example, please? :)
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

the lib doesn't seem to work with this after conversion:

Code: Select all

Set objWMIService = GetObject("winmgmts:\\" & _
    strComputer & "\root\cimv2")

I probably did something wrong tho. I dont get where to put the "'s for the '& _strComputer & ' part.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

OK, i'm having a terrible time with getting the lib to work for vbs, i'm adapting one of your examples for use.

First, this is the original .vbs from the MSDN:

Code: Select all

strComputer = "."
Set objWMIService = GetObject( _ 
    "winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration ")
 
For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then 
        For i=LBound(IPConfig.IPAddress) _
            To UBound(IPConfig.IPAddress)
                WScript.Echo IPConfig.IPAddress(i)
        Next
    End If
Next
And next this is the code as i have it right now:

Code: Select all

Procedure.s AdapterConfig() ; Returns AdapterConfig

   Protected Script$ 
      
      strComputer.s = Chr(34) + "." + Chr(34) + #CRLF$
    	Script$ = "Set objWMIService = GetObject(" + Chr(34) + "winmgmts:" + Chr(34) + " _" + #CRLF$
    	Script$ + "    & " + Chr(34) + "{impersonationLevel=impersonate}!\\" + Chr(34) + " & strComputer & " + Chr(34) + "\root\cimv2" + Chr(34) + ")" + #CRLF$
    	Script$ + "Set IPConfigSet = objWMIService.ExecQuery _" + #CRLF$
    	Script$ + "    (" + Chr(34) + "Select IPAddress from Win32_NetworkAdapterConfiguration" + Chr(34) + ")" + #CRLF$
    	Script$ + "For Each IPConfig in IPConfigSet" + #CRLF$
    	Script$ + "    If Not IsNull(IPConfig.IPAddress) Then " + #CRLF$
    	Script$ + "        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)" + #CRLF$
    	Script$ + "            name = name & IPConfig.description(i) & vbTab & IPConfig.IPAddress(i) & vbCrlf" + #CRLF$
    	Script$ + "        Next" + #CRLF$
    	Script$ + "    End If" + #CRLF$
    	Script$ + "Next" + #CRLF$
     
   ProcedureReturn Script$ 
EndProcedure


dhToggleExceptions(#True)

Define.l Result, obj = dhCreateObject("MSScriptControl.ScriptControl")
Define.s Script

If obj

  dhPutValue(obj, "Language = %T", @"VBScript")
  dhGetValue("%T", @Result, obj, "Language")

  If Result

    Debug "Language: " + PeekS(Result)
    dhFreeString(Result) : Result = 0

  EndIf

  ;dhPutValue(obj, "TimeOut = %d", 20000)
  dhGetValue("%d", @Result, obj, "TimeOut")

  Debug "TimeOut: " + Str(Result) + " ms"
  Script = AdapterConfig()
  dhCallMethod(obj, "AddCode(%T)", @Script)
  dhGetValue("%T", @Result, obj, "Eval(%T)", @"myTitle")

  If Result

    Debug "Adapter:" + PeekS(Result)
    dhFreeString(Result) : Result = 0

  EndIf

  dhReleaseObject(obj) : obj = 0

EndIf
I'm using your vbs.pb as a sort of guide, but i'm not sure if i even have it correct. Doesn't work, what am i doing wrong (probably everything) ?
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Post by ts-soft »

Code: Select all

       Script$ + "            name = name & IPConfig.description(i) & vbTab & IPConfig.IPAddress(i) & vbCrlf" + #CRLF$ 

Code: Select all

dhGetValue("%T", @Result, obj, "Eval(%T)", @"myTitle") 
No time to test, but you use name for the result in script and myTitle to get the result.


// edit

Code: Select all

Procedure.s AdapterConfig() ; Returns AdapterConfig

   Protected Script$
     
       Script$ = "Set objWMIService = GetObject(" + Chr(34) + "winmgmts:" + Chr(34) + " _" + #CRLF$
       Script$ + "    & " + Chr(34) + "{impersonationLevel=impersonate}!\\.\root\cimv2" + Chr(34) + ")" + #CRLF$
       Script$ + "Set IPConfigSet = objWMIService.ExecQuery _" + #CRLF$
       Script$ + "    (" + Chr(34) + "Select IPAddress from Win32_NetworkAdapterConfiguration" + Chr(34) + ")" + #CRLF$
       Script$ + "For Each IPConfig in IPConfigSet" + #CRLF$
       Script$ + "    If Not IsNull(IPConfig.IPAddress) Then " + #CRLF$
       Script$ + "        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)" + #CRLF$
       Script$ + "            name = name & IPConfig.description(i) & vbTab & IPConfig.IPAddress(i) & vbCrlf" + #CRLF$
       Script$ + "        Next" + #CRLF$
       Script$ + "    End If" + #CRLF$
       Script$ + "Next" + #CRLF$
     
   ProcedureReturn Script$
EndProcedure

SetClipboardText(AdapterConfig())
Save the clipboard to bla.vbs and you will see a error in line 8
"IPConfig.description(i)"
Remove the error from your script and make the changes of eval!
I'm not a vb-scripter and the methode "AddCode" is not supported in
Vista, so i can't test it

greetings
Thomas
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply