COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
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 »

Marco2007 wrote:I bought the license for two years.
AVIRA AntiVirus barks only with Debugger enabled
:wink:
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
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

@TS-Soft: Thanx for the info! You`re right!

@Berikco: Image Image Image
PureBasic for Windows
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

srod,

Very Nice, its already helpful in a project i'm working on. Thank you very much.

Tried it out on some vbs i had laying around, doesn't work in this type of vbs code tho:

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 the flash demo doesn't work here on Vista Ultimate
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 »

> and the flash demo doesn't work here on Vista Ultimate
copy the flash to c: or change the path in the example. a absolute path is
required!

Works fine on Vista Ultimate 64 :wink:
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Yes the flash demo requires an absolute url.

As for the VB code, you'd have to be more specific. I haven't added a FOREACH / NEXT macro and so you'll need to use the COMate_EnumObject() objects to enumerate the collection etc. Let me try and translate your code and see what happens?

I am just working on the ocx controls right now which is just about finished.

**EDIT : SFSxOI, your VB code is running fine here -at least up to a point. However, it uses SafeArrays and so I need to rummage around a bit before it will run! :)
I may look like a mule, but I'm not a complete ass.
X
Enthusiast
Enthusiast
Posts: 311
Joined: Tue Apr 04, 2006 6:27 am

Post by X »

SFSxOI wrote:srod,

Very Nice, its already helpful in a project i'm working on. Thank you very much.

Tried it out on some vbs i had laying around, doesn't work in this type of vbs code tho:

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 the flash demo doesn't work here on Vista Ultimate
Can you provide an example on how you called that VBS script? Did you (or have you?) found a way to call PB functions from VBS?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@SFXxOI : I can get the following to work okay :

Code: Select all

XIncludeFile "COMate.pbi"

Define.COMateObject objWMIService, processorObject
collection.COMateEnumObject

strComputer.s = "."

objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
  collection = objWMIService\CreateEnumeration("ExecQuery('Select * from Win32_Processor')")
  If collection
    processorObject = collection\GetNextObject()
    While processorObject
      Debug processorObject\GetStringProperty("currentClockSpeed")
      processorObject\Release()
      processorObject = collection\GetNextObject()
    Wend
  EndIf  
EndIf 
and so your VB code should not be a problem.

However, I was getting to the SafeArray part of the code you posted when I realised that I was getting just null returns from the enumeration. Now I think this is because of my computer setup rather than a problem with COMate. Can you give me a little more background as to what your script does and does my computer, for example, need to be part of a network or some such in order for your VB code to produce results? It is difficult to finish translating your VBS snippet without knowing what I should be expecting? :)
I may look like a mule, but I'm not a complete ass.
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 »

> I can get the following to work okay
There comes only one speed on my dual core? Is this okay?
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
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

I guess so! :) I only get one result as well.
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

SFSxOI : can you run the following to see what kind of variants are being returned? I need to know the value being debugged?

Code: Select all

XIncludeFile "COMate.pbi"

Define.COMateObject objWMIService, IPConfig
IPConfigSet.COMateEnumObject
*var.VARIANT

strComputer.s = "."

objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "")
If objWMIService
  IPConfigSet = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
  If IPConfigSet
    IPConfig = IPConfigSet\GetNextObject()
    While IPConfig
      If IPConfig
        *var = IPConfig\GetVariantProperty("IPAddress")
        Debug *var\vt
        
        VariantClear_(*var)
        IPConfig\Release()
      EndIf
      IPConfig = IPConfigSet\GetNextObject()
    Wend


  EndIf  
EndIf 
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@Kiffi, I have your VB ActiveX code running okay. I just need to make a change to COMate... :wink: I am guessing, but I don't think even DispHelper would work with this code of yours?

**EDIT : Here's the COMate code :

Code: Select all

XIncludeFile "COMate.pbi"

object.COMateObject

a.l = 20

object = COMate_CreateObject("ActiveXTest.clsActiveXTest")

If object = 0
  COMate_RegisterActiveXServer("Projekt1.dll")
  object = COMate_CreateObject("ActiveXTest.clsActiveXTest")
EndIf

If object
  object = COMate_CreateObject("ActiveXTest.clsActiveXTest")
  If object
    object\Invoke("Test1(" + Str(@a) + " as long BYREF)")    
    object\Release()
  EndIf
  COMate_UnRegisterActiveXServer("Projekt1.dll", #False)
  Debug "New value of a is " + Str(a)
EndIf
As you can see I have added a 'BYREF' modifier for parameters. With VB com servers it is not enough to simply pass the address of a variable to a VB method expecting an address... you also have to specify that the parameter is a pointer in the underlying variant! I know for a fact that DispHelper doesn't do this!

You will have to wait until I upload an update to COMate in order to run this as I am still working on the OCX stuff (just converting examples now) and I wish to get to the bottom of SFSxOI's problem. Although I think that his problematic code is just one of using safearrays etc. :)
Last edited by srod on Thu Sep 04, 2008 2:07 am, edited 1 time in total.
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

srod wrote:SFSxOI : can you run the following to see what kind of variants are being returned? I need to know the value being debugged?

Code: Select all

XIncludeFile "COMate.pbi"

Define.COMateObject objWMIService, IPConfig
IPConfigSet.COMateEnumObject
*var.VARIANT

strComputer.s = "."

objWMIService = COMate_GetObject("winmgmts:\" + strComputer + "\root\cimv2", "")
If objWMIService
  IPConfigSet = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")
  If IPConfigSet
    IPConfig = IPConfigSet\GetNextObject()
    While IPConfig
      If IPConfig
        *var = IPConfig\GetVariantProperty("IPAddress")
        Debug *var\vt
        
        VariantClear_(*var)
        IPConfig\Release()
      EndIf
      IPConfig = IPConfigSet\GetNextObject()
    Wend


  EndIf  
EndIf 
This is what your above returns:

Code: Select all

1
1
1
1
8204
1
1
1
1
1
1
and this is the code I was using after converting the vbs and using your include:

Code: Select all

Define.COMateObject objWMIService, IPConfig
Define.s strComputer = "."

objWMIService = COMate_GetObject("winmgmts:\" + strComputer + "\root\cimv2", "") 
If objWMIService 
  IPConfig = objWMIService\ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration") 
  If IPConfig 
    While IPConfig 
        Debug IPConfig\IPAddress 
      EndIf 
    Wend 
  EndIf  
EndIf
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

The code you just posted... well, I'm sorry, but it's nowhere near a valid translation to Purebasic with COMate! :) You're attempting to execute COM methods on internal COMate objects! You have also not created an enumeration of IPAddress objects etc. Someone hasn't read the COMate manual! :wink: You need to look at the code of mine which you ran as a test, that is how we must proceed. What your test has confirmed is that we simply need to complete the code.

The 8204 was what I was after! :wink: The 1's represent null returns, presumably from adapters with no ip address. You should modify the query to filter these values out. Should be easy enough.

The 8204 tells us that one adaptor does indeed have an ip address and the enumeration has returned a safearray of variants! All we need to do is figure out how to get our hands on the array and then the variants within the array! :wink: Difficult for me because I can't run the code in order to make tests as I proceed etc; I have no network adapters yielding any results and I do not have enough experience with SafeArrays to figure out the code whilst running blind!

Still, I'll certainly have a look tomorrow. :)
I may look like a mule, but I'm not a complete ass.
byo
Enthusiast
Enthusiast
Posts: 635
Joined: Mon Apr 02, 2007 1:43 am
Location: Brazil

Post by byo »

srod, it's ingenious. Thank you.
Proud registered Purebasic user.
Because programming should be fun.
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Post by Michael Vogel »

Just loaded the examples but have a small problem with Demo_Agent.pb:

when the user closes the agent 'manually' (right click and "hide"), the program still continues with its steps. How can I recognize that the agent has been closed? All invokes lines still return '0' and GetProperties returns the same pointer.

Any :idea:
Post Reply