COMate - control COM objects via automation - OBSOLETE!

Developed or developing a new product in PureBasic? Tell the world about it.
jpd
Enthusiast
Enthusiast
Posts: 167
Joined: Fri May 21, 2004 3:31 pm

Post by jpd »

Hi,

I search to use the methode EnableStatic for change the IPAddress
on the NetAdapter..

using the class Win32_NetworkAdapterConfiguration

this error appair
-2147024809
One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so, try splitting your method call into two or more subcalls.
any idea ?


Code: Select all

;/////////////////////////////////////////////////////////////////////////////////
;***COMate***  COM automation through iDispatch.
;*===========
;*
;*WMI demo - renew IP addresses. By SFSxOI.
;/////////////////////////////////////////////////////////////////////////////////

IncludePath "..\..\"
XIncludeFile "COMate.pbi"
XIncludeFile "VariantHelper_Include.pb"
Define.COMateObject objWMIService, objNetCard 
colNetCards.COMateEnumObject 
Define *IPAddress.VARIANT,*ConnectID.VARIANT, *varIP.VARIANT
  *sa.SafeArray
strComputer.s = "." 

objWMIService = COMate_GetObject("winmgmts:\\" + strComputer + "\root\cimv2", "") 
If objWMIService 
  colNetCards = objWMIService\CreateEnumeration("ExecQuery('Select IPAddress from Win32_NetworkAdapterConfiguration')")  
  If colNetCards 
  
    objNetCard = colNetCards\GetNextObject() 
    While objNetCard 
    ;Debug objNetCard\GetstringProperty("IPAddress")
    *IPAddress= objNetCard\GetvariantProperty("IPAddress") 
        If *IPAddress\vt <> #VT_NULL
          *sa = *IPAddress\parray
          For i = saLBound(*sa) To saUBound(*sa)
            *varIP = SA_VARIANT(*sa, i)
            If *varIP\vt <> #VT_BSTR
              VariantChangeType_(*varIP, *varIP, 0, #VT_BSTR)
            EndIf
            sIPAddress.s= PeekS(*varIP\bstrVal, -1, #PB_Unicode)
            If sIPAddress="192.168.65.5"
            ;objNetCard\SetProperty("EnableStatic'(192.168.66.5,255.255.255.0)'") 
            objNetCard\SetProperty("EnableStatic($0027"+"192.168.66.5,255.255.255.0"+"$0027)") 
           Debug  COMate_GetLastErrorCode() 
           Debug COMate_GetLastErrorDescription() 

          EndIf
            VariantClear_(*varIP)
            
          Next
          saFreeSafeArray(*sa)
        EndIf
        VariantClear_(*IPAddress) : FreeMemory(*IPAddress)
        
      objNetCard\Invoke("RenewDHCPLease()") 
      objNetCard\Release() 
      objNetCard = colNetCards\GetNextObject() 
    Wend 
    colNetCards\Release() 
  EndIf 
  objWMIService\Release()  
Else
  MessageRequester("COMate - WMI demo", "Couldn't create the WMI scripting object!")
EndIf 
Thanks
jpd
PB 5.10 Windows 7 x64 SP1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Beyond my experience I'm afraid and not a COMate issue as such! :)

A quick search throws up the following :
http://msdn.microsoft.com/en-us/library/aa390383.aspx and http://forums.microsoft.com/MSDN/ShowPo ... 5&SiteID=1 both of which suggest that you need to be passing two arrays as parameters to the EnableStatic() property.

To pass a safe array to a dispinterface requires that you wrap it up in a variant structure first and pass it that way. See Num3's code earlier on in this thread for an example of doing that.
I may look like a mule, but I'm not a complete ass.
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

COMATE <-> SAP

Post by glops »

I tried to connect to SAP with COMate, and LOGON/LOGOFF are ok
Here is a link with an example
http://searchsap.techtarget.com/expert/ ... 45,00.html

Code: Select all

IncludePath "..\"
XIncludeFile "COMate.pbi"

Define.COMateObject LogonControl
Define.COMateObject R3Connection
Define.COMateObject funcControl
Define.COMateObject RFC
Define.COMateObject TableFactory

LogonControl = COMate_CreateObject("SAP.LogonControl.1")
FuncControl = COMate_CreateObject("SAP.Functions") 
TableFactory = COMate_CreateObject("SAP.TableFactory.1") 

If LogonControl
    R3Connection = LogonControl\GetObjectProperty("NewConnection")
    ;R3Connection = FuncControl\GetObjectProperty("Connection")
    R3Connection\SetProperty("System = '???'")
    R3Connection\SetProperty("ApplicationServer = 'frmXXXXXX'")
    R3Connection\SetProperty("SystemNumber = '01'")
    
    R3Connection\SetProperty("Client = '010'")
    R3Connection\SetProperty("User = 'user'")
    R3Connection\SetProperty("Password = 'mypwd'")
    R3Connection\SetProperty("Language = 'EN'")

    retcd = R3Connection\Invoke("Logon(0, #True)")


here if you check with SM04, you can see the connection
but now...how to translate

;Functions.Connection = R3Connection
;Set Func = Functions.Add("RFC_GET_TABLE_ENTRIES")
;Set iTABLE_NAME = Func.Exports("TABLE_NAME")
;Set eNUMBER_OF_ENTRIES = Func.Imports("NUMBER_OF_ENTRIES")
;Set tENTRIES = Func.Tables("ENTRIES")
;iTABLE_NAME.Value = "TCURR"
;Func.Call

Code: Select all


    R3Connection\Invoke("Logoff")
    Debug     COMate_GetLastErrorCode() 
    
    R3Connection\Release()
endif
I tried a lot of combinations, but always errors..methods don' exist...etc
Can someone help me ? thx
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Functions.Connection = R3Connection
Ah, COMate cannot do that!!!

I'll have to give that some thought.
I may look like a mule, but I'm not a complete ass.
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

Post by glops »

Functions.Connection = R3Connection

That's not the more difficult problem...We can replace it directly by calling
R3Connection = FuncControl\GetObjectProperty("Connection")
without calling the "SAP.LogonControl.1"

but I believe real problem is ....I don't know how to translate
;Set Func = Functions.Add("RFC_GET_TABLE_ENTRIES")
;Set iTABLE_NAME = Func.Exports("TABLE_NAME")
;Set eNUMBER_OF_ENTRIES = Func.Imports("NUMBER_OF_ENTRIES")
;Set tENTRIES = Func.Tables("ENTRIES")

I have messages like
One or more arguments are invalid. Possibly a numerical overflow or too many nested objects, -if so, try splitting your method call into two or more subcalls.
or
Method/property not supported by this object.


:(
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Something doesn't seem right here with what you are posting? FuncControl, functions, func.... Something is not right.

If I were you I would try a 100% translation of the VB code you have posted. At the moment you seem to have drifted. Yes you will have to get around the
Functions.Connection = R3Connection
problem.

The only real 'concern' I would have is in exactly what kind of object tENTRIES is? Is it an array of objects? Is it a 2-dimensional safearray? You need to get to the bottom of that first.
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 »

@glops, can you try the following - incomplete as it is. I am guessing a bit because I do not have access to the relevant ActiveX dll's etc. Note the comment in the code.

Code: Select all

IncludePath "..\" 
XIncludeFile "COMate.pbi" 


Define.COMateObject Functions, LogonControl, R3Connection, func, iTABLE_NAME, eNUMBER_OF_ENTRIES, tENTRIES

LogonControl = COMate_CreateObject("SAP.LogonControl.1")
If LogonControl
  Functions = COMate_CreateObject("SAP.Functions")
  If Functions
    R3Connection = Functions\GetObjectProperty("Connection") 
    If R3Connection
      R3Connection\SetProperty("System = '???'") 
      R3Connection\SetProperty("ApplicationServer = 'frmXXXXXX'") 
      R3Connection\SetProperty("SystemNumber = '01'") 
    
      R3Connection\SetProperty("Client = '010'") 
      R3Connection\SetProperty("User = 'user'") 
      R3Connection\SetProperty("Password = 'mypwd'") 
      R3Connection\SetProperty("Language = 'EN'") 

      retcd = R3Connection\Invoke("Logon(0, #True)")   ;Does this need to be retcd = R3Connection\GetIntegerProperty("Logon(0, #True)") ???
      func = Functions\GetObjectProperty("Add('RFC_GET_TABLE_ENTRIES')") 
      If func
        eNUMBER_OF_ENTRIES = func\GetObjectProperty("NUMBER_OF_ENTRIES")
        If eNUMBER_OF_ENTRIES
          iTABLE_NAME = func\GetObjectProperty("TABLE_NAME")
          If iTABLE_NAME
            tENTRIES = func\GetObjectProperty("Tables('ENTRIES')")
            If tENTRIES
              iTABLE_NAME\SetProperty("Value = 'TCURR')")
              func\Invoke("Call")
Debug "Number of entries = " + Str(eNumber_OF_ENTRIES\GetIntegerProperty("Value"))


              tENTRIES\Release()
            EndIf
            iTABLE_NAME\Release()
          EndIf
          eNUMBER_OF_ENTRIES\Release()
        EndIf
        func\Release()      
      EndIf
      R3Connection\Release()
    EndIf  
    Functions\Release()
  EndIf
  LogonCOntrol\Release()
EndIf
I may look like a mule, but I'm not a complete ass.
Marco2007
Enthusiast
Enthusiast
Posts: 648
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

Nice, now I know what I will try to do on monday at work :D
SAP and PB, that`s like sleeping pills and cocaine
:D

Thanx for the link, glops.
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 »

I think its supposed to be like you have it srod:

Code: Select all

retcd = R3Connection\Invoke("Logon(0, #True)")

and not:

retcd = R3Connection\GetIntegerProperty("Logon(0, #True)")
 
because there aren't any properties to get, just something to do.


but this line:

Code: Select all

func = Functions\GetObjectProperty("Add('RFC_GET_TABLE_ENTRIES')") 
should that not be:

Code: Select all

func = Functions\Invoke("Add('RFC_GET_TABLE_ENTRIES')") 
?
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Invoke does not return any values; so no! :)

If you are expecting a return value of any kind from the COM object and that value is required to be used at some point then you MUST use one of the GetxxxProperty() calls. Invoke() is for those methods with no returns or those cirumstances where you don't care about the return from the COM object etc.

In short, GetxxxProperty() can be used wherever Invoke() can be used but the GetxxxProperty() calls are the only way of retrieving a value/object from the COM object.
I may look like a mule, but I'm not a complete ass.
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

Post by glops »

Srod, I changed a little your code, return after "call" = Okay
but I cannot get the result from NUMBER_OF_ENTRIES
Will continue next week, thxs already for your help ...

Code: Select all

      retcd = R3Connection\Invoke("Logon(0, #True)")   ;Does this need to be retcd = R3Connection\GetIntegerProperty("Logon(0, #True)") ??? 
      func = Functions\GetObjectProperty("Add('RFC_GET_TABLE_ENTRIES')") 
      If func 
       ; eNUMBER_OF_ENTRIES = func\GetIntegerProperty("NUMBER_OF_ENTRIES") 
       ; If eNUMBER_OF_ENTRIES 
          eNUMBER_OF_ENTRIES = func\GetObjectProperty("Imports('NUMBER_OF_ENTRIES')") 
          iTABLE_NAME = func\GetObjectProperty("Exports('TABLE_NAME')") 
          If iTABLE_NAME 
           ; tENTRIES = func\GetObjectProperty("Tables('ENTRIES')") 
           ; If tENTRIES 
              iTABLE_NAME\SetProperty("Value = 'TCURR')") 
              func\Invoke("Call") 
;Debug "Number of entries = " + Str(eNumber_OF_ENTRIES\GetIntegerProperty("Value")) 

 Debug COMate_GetLastErrorDescription(); "Okay in debug *eNUMBER_OF_ENTRIES = 3874576
 
 
 ;eMAXIMAL_RESOURCES = func\GetIntegerProperty("NUMBER_OF_ENTRIES") 
 Debug eNUMBER_OF_ENTRIES\GetIntegerProperty("NUMBER_OF_ENTRIES") ; result = 0 should be 13190
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Whoops, yes - silly me! :)

However your last line doesn't look right :

Code: Select all

Debug eNUMBER_OF_ENTRIES\GetIntegerProperty("NUMBER_OF_ENTRIES") ; result = 0 should be 13190
From what little I could find on the web you want :

Code: Select all

Debug eNUMBER_OF_ENTRIES\GetIntegerProperty("Value") ; result = 0 should be 13190
but if you're telling me that doesn't work......
I may look like a mule, but I'm not a complete ass.
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

Post by glops »

....it does not work.... :wink:
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

And what does COMate_GetLastErrorDescription() say when using the version which you posted?
I may look like a mule, but I'm not a complete ass.
glops
User
User
Posts: 38
Joined: Wed Jan 16, 2008 12:53 pm
Location: France

Post by glops »

Okay.
0
0
0

0
Okay.
Post Reply