` Printed Icetips Article

Icetips Article



Windows API: Item method implementation in OLE
2004-01-10 -- Michael Ware
 
Newsgroups: softvelocity.clarion.language

Jim,
Brilliant Thanks!!  Using your tips I can now check the state of a service using:

 ! Check if the "Schedule" Service is running.
     ?ocxobject{prop:reportexception}=true
     ?ocxobject{prop:create}='WbemScripting.SWbemLocator'
     objsvs=?ocxobject{'connectserver(,,,,,,,)'}
     OBJSub  = ?OcxObject{objsvs & '.GET(Win32_Service.Name=''Schedule'')'}
     Message('service.NAME:' & ?OcxObject{OBJSub & '.NAME'})
     Message('service.State:' & ?OcxObject{OBJSub & '.State'})
     Message('service.Start Mode:' & ?OcxObject{OBJSub & '.StartMode'})
     Message('service.Status:' & ?OcxObject{OBJSub & '.Status'} )
     ?ocxobject{prop:release}=OBJSub
     ?ocxobject{prop:release}=OBJsvs

But I've reached the end of my rope trying to implement calls to _newenum.  The
following returns an IDispatch object into objEnum.  But any attempt to access it
through the OLE control GPF.

  objOS = (?OcxObject{objsvs & '.ExecQuery("Select * from Win32_QuickFixEngineering")'})

  Message('OS=' & objOS) ! shows "`5474248"
  BIND('IDispInterface',IDispInterface)
  objEnum  = ?OcxObject{objOS & '._newenum(&IDispINTERFACE)'}
  objEnum[1] = '`'  ! (replace chr(0) so this looks like a prop:object)
  Message('Enum=' & objEnum) ! shows "`5474064"
  BIND('objNxtArray',objNxtArray)
  BIND('lNxtCount',lNxtCount)
  objItem = ?OcxObject{objEnum & '.Next(1,&objNxtArray,&lNxtCount)'} !GPF

I suspect you had a good reason for using "a bit of assembler". .  I'm going to
move on and try to get a "small" VB or VC exe that I can shell too to pull the data.
My targets here are the hot fixes (Win32_QuickFixEngineering) and OS data
(Win32_OperatingSystem).

Thanks again for the support.  If anyone wants to FAQ the code for getting Service
data feel free.

-Mike



"jim kane"  wrote in message
news:A921.1072838395.5597@discuss.softvelocity.com...
> I looked more closely at what you had done and looked back at some work on
> wmi I did a long, long time ago.  I was very fortunate on that project as
> the network admin set everything up and wrote all the ldap queries.
>
> In any case the getobject is a com interface method.  You're in essence
> trying to start in the middle of the story.  The 1st step which your not
> doing is to use the wmi locator to connect to a wmi server.  BTW the wmi
> services need to be running.
> The code to do that is:
> COUNT  LONG
> objsvs cstring(20)
> objos  cstring(20)
>     CODE
>
>
>     OPEN(MainWin)
>     DISPLAY
>     ACCEPT
>         CASE EVENT()
>         OF EVENT:OpenWindow
>             ?ocxobject{prop:reportexception}=true
>             ?ocxobject{prop:create}='WbemScripting.SWbemLocator'
>             objsvs=?ocxobject{'connectserver(,,,,,,,)'}
>
>         OF EVENT:Accepted
>             CASE FIELD()
>             OF ?Exit
>                 POST(EVENT:CloseWindow)
>             OF ?GetOS
>                 objos = (?OcxObject{objsvs & '.ExecQuery("Select * from
> Win32_OperatingSystem")'})
>                 Message('ObjOS: '& objos)
>                 message(?ocxobject{objos & '.count'})  !displays '1'
>                 ?ocxobject{prop:release}=objos
>
> the next important thing is that you get OLE view and open the typelibary.
> it's in the same folder as the .dll and called WBEMDISP.TLB - if you search
> your hard drive you have it.
> if you open in in ole view and search for the execquery method you will find
> it returns a ISWbemObjectSet.  As you pointed out earlier that object's item
> method is difficult to work with.  The way arround that is the object has a
> _newenum method.  VB supports that with the 'for each' syntax but clarion
> does not.  You can write your own code to call via IDispatch to get the
> IEnum interface returned by _NEWENUM and use it's next method to loop thru
> all the objects in the set.  I have never needed to do that because usually
> the objects provide their own explicit next method or the item method is
> easier to use.  I did do it once back when I was first starting with come
> using a bit of assembler I published long ago in clairon mag but have neve
> had a need to update it so I cant really help you.  If you are serious about
> wmi you'll need to attack that beast.
>
> the call to .get that followed does not return the same type of object and
> the object returned is not a collection so .count or .item does not work on
> it.  I did not look how to use the Iwbemobject type of object that it
> returns.
>
> As a final word of advice, you will need to constantly be thinking about
> each object you acquire and remember for call release to avoid memory leaks.
>
> Jim Kane
>



Printed November 23, 2024, 3:34 am
This article has been viewed/printed 35229 times.
Google search has resulted in 218 hits on this article since January 25, 2004.