Only because I made the same mistake!SFSxOI wrote:yep, you guessed it
COMate - control COM objects via automation - OBSOLETE!
What is error code :
Unknown error. (Code : Hex FFFFFFFF80020003). Please report this error code to the author at 'enquiries@nxsoftware.com'
?
generated from this code:
The original function is:
located at: http://msdn.microsoft.com/en-us/library ... S.85).aspx
I also tried SetPropertyRef and Invoke.
Invoke goves "Type mismatch in the method parameters."
SetPropertyRef give the unknown error
I also tried various type modifiers also.
[/code]
Unknown error. (Code : Hex FFFFFFFF80020003). Please report this error code to the author at 'enquiries@nxsoftware.com'
?
generated from this code:
Code: Select all
#NET_FW_IP_PROTOCOL_TCP = 6
#NET_FW_ACTION_ALLOW = 1
Procedure AdvFireWall_LanRuleAdd()
Define fwPolicy2.COMateObject
Define RulesObject.COMateObject
Define NewRule.COMateObject
Name$ = "Per_InterfaceType_Rule"
Description$ = "Allow incoming network traffic over port 2400 coming from LAN interfcace type"
LocalPorts$ = Str(2300)
Interfacetypes$ = "All"
Grouping$ = "@firewallapi.dll,-23255"
fwPolicy2 = COMate_CreateObject("HNetCfg.FwPolicy2")
RulesObject = fwPolicy2\GetObjectProperty("Rules()") ; INetFwRules object
CurrentProfiles = fwPolicy2\GetIntegerProperty("CurrentProfilesTypes()")
NewRule = COMate_CreateObject("HNetCfg.FWRule") ; INetFwRule object
NewRule\SetProperty("Name(" + Name$ + ")")
NewRule\SetProperty("Description(" + Description$ + ")")
NewRule\SetProperty("Protocol(" + Str(#NET_FW_IP_PROTOCOL_TCP) + ")")
NewRule\SetProperty("LocalPorts(" + LocalPorts$ + ")")
NewRule\SetProperty("Interfacetypes(" + Interfacetypes$ + ")")
NewRule\SetProperty("Enabled(" + Str(#True) + ")")
NewRule\SetProperty("Grouping(" + Grouping$ + ")")
NewRule\SetProperty("Profiles(" + Str(CurrentProfiles) + ")")
NewRule\SetProperty("Action(" + Str(#NET_FW_ACTION_ALLOW) + ")")
RulesObject\SetProperty("Add(" + Str(NewRule) + ")")
Debug COMate_GetLastErrorDescription()
NewRule\Release()
RulesObject\Release()
fwPolicy2\Release()
EndProcedure
generated when this line is used:
RulesObject\SetProperty("Add(" + Str(NewRule) + ")")
(everything else above that reports as OK)
Code: Select all
Add(
[in] INetFwRule *rule
);
I also tried SetPropertyRef and Invoke.
Invoke goves "Type mismatch in the method parameters."
SetPropertyRef give the unknown error
I also tried various type modifiers also.
[/code]
That error code is #DISP_E_MEMBERNOTFOUND and should be recognised by COMate! That is strange. Have you altered the COMate source by any chance because this is the second time now that you are reporting errors which differ from my version - errors which do not make any sense!
However, the line you refer to looks very wrong. Did you try the " as COMateObject" modifier?
Note that it really does look to be 'Invoke' in this case.
However, the line you refer to looks very wrong. Did you try the " as COMateObject" modifier?
Code: Select all
RulesObject\Invoke("Add(" + Str(NewRule) + " as COMateobject)") I may look like a mule, but I'm not a complete ass.
Yep, I tried the Invoke;
That was actually the very first thing I tried because it did indeed look like an invoke to be used here, the Invoke gives a different error of "Type mismatch in the method parameters." but there isn't a mismatch . I also tried the SetProperty, SetPropertyRef, and variations on GetIntergerProperty and stuff like that (even though this doesn't return anything). I also went thru most of the type modifiers as well.
hmmmm...nope, haven't changed the COMate source in anyway. In fact everytime I start something new I use a fresh unzipped COMate source and the latest I have is right from your download at the site.
Code: Select all
RulesObject\Invoke("Add(" + Str(NewRule) + " as COMateobject)")
hmmmm...nope, haven't changed the COMate source in anyway. In fact everytime I start something new I use a fresh unzipped COMate source and the latest I have is right from your download at the site.
SFSxOI, this code should run fine... except that you have made some baaaaaaaaaaaad ass mistakes!
All of your \SetProperty() calls are invalid.
Try the following which I haven't tested and you will need to check for typos etc.
All of your \SetProperty() calls are invalid.
Try the following which I haven't tested and you will need to check for typos etc.
Code: Select all
#NET_FW_IP_PROTOCOL_TCP = 6
#NET_FW_ACTION_ALLOW = 1
Procedure AdvFireWall_LanRuleAdd()
Define fwPolicy2.COMateObject
Define RulesObject.COMateObject
Define NewRule.COMateObject
Name$ = "Per_InterfaceType_Rule"
Description$ = "Allow incoming network traffic over port 2400 coming from LAN interfcace type"
LocalPorts$ = Str(2300)
Interfacetypes$ = "All"
Grouping$ = "@firewallapi.dll,-23255"
fwPolicy2 = COMate_CreateObject("HNetCfg.FwPolicy2")
RulesObject = fwPolicy2\GetObjectProperty("Rules()") ; INetFwRules object
CurrentProfiles = fwPolicy2\GetIntegerProperty("CurrentProfilesTypes()")
NewRule = COMate_CreateObject("HNetCfg.FWRule") ; INetFwRule object
NewRule\SetProperty("Name = '" + Name$ + "'")
NewRule\SetProperty("Description = '" + Description$ + "'")
NewRule\SetProperty("Protocol = " + Str(#NET_FW_IP_PROTOCOL_TCP))
NewRule\SetProperty("LocalPorts = '" + LocalPorts$ + "'")
NewRule\SetProperty("Interfacetypes = '" + Interfacetypes$ + "'")
NewRule\SetProperty("Enabled = #True")
NewRule\SetProperty("Grouping = '" + Grouping$ + "'")
NewRule\SetProperty("Profiles = " + Str(CurrentProfiles))
NewRule\SetProperty("Action = " + Str(#NET_FW_ACTION_ALLOW))
RulesObject\Invoke("Add(" + Str(NewRule) + " as comateobject)")
Debug COMate_GetLastErrorDescription()
NewRule\Release()
RulesObject\Release()
fwPolicy2\Release()
EndProcedure
I may look like a mule, but I'm not a complete ass.
With your code above I now get a "An exception occurred during the execution of this method/property." error at the last line at:
If i comment out that line and do a "Debug COMate_GetLastErrorDescription()" it returns OK.
I don't understand it, this should be an Invoke and working.
I have another question for you also. I happen to look at this line again:
After reading the MSDN again, I don't think thats correct. The MSDN says that:
"profileTypesBitmask [out]
Pointer to a buffer that receives the bitmask of the currently active profile from NET_FW_PROFILE_TYPE2."
and if it suceeds it "If the method succeeds, the return value is S_OK." So I happen to look at the value of CurrentProfiles and it is indeed 0 which is #S_OK. So what its returning in CurrentProfiles is really just telling me that it suceeded. So the question is this; How do you return a pointer to a buffer from this using COMate? Like this:
Code: Select all
RulesObject\Invoke("Add(" + Str(NewRule) + " as comateobject)")
I don't understand it, this should be an Invoke and working.
I have another question for you also. I happen to look at this line again:
Code: Select all
CurrentProfiles = fwPolicy2\GetIntegerProperty("CurrentProfilesTypes()")
"profileTypesBitmask [out]
Pointer to a buffer that receives the bitmask of the currently active profile from NET_FW_PROFILE_TYPE2."
and if it suceeds it "If the method succeeds, the return value is S_OK." So I happen to look at the value of CurrentProfiles and it is indeed 0 which is #S_OK. So what its returning in CurrentProfiles is really just telling me that it suceeded. So the question is this; How do you return a pointer to a buffer from this using COMate? Like this:
Code: Select all
CurrentProfiles = fwPolicy2\GetIntegerProperty("CurrentProfilesTypes(@profileTypesBitmask)")
??????
Try
As for your exception... no idea.
**EDIT : correction; you will probably need to use : and
in place of your original line.
Code: Select all
CurrentProfiles = fwPolicy2\Invoke("CurrentProfilesTypes(" + str(@profileTypesBitmask) + " BYREF)")
**EDIT : correction; you will probably need to use :
Code: Select all
fwPolicy2\Invoke("CurrentProfilesTypes(" + str(@profileTypesBitmask) + " BYREF)")Code: Select all
NewRule\SetProperty("Profiles = " + Str(profileTypesBitmask)) in place of your original line.
I may look like a mule, but I'm not a complete ass.
Finally!
This works!
Heres the code...and thank you very much for your help 
Note: Vista Only
and not even any need to go any further with building on this because the rest with adding apps and stuff to the advanced firewall in Vista looks exactly like this except for changing out a property or two, so this makes a good template for this purpose.
This works!
Code: Select all
RulesObject\GetIntegerProperty("Add(" + Str(NewRule) + " as COMateobject)")
Note: Vista Only
Code: Select all
Procedure AdvFireWall_LanRuleAdd()
Define fwPolicy2.COMateObject
Define RulesObject.COMateObject
Define NewRule.COMateObject
#NET_FW_IP_PROTOCOL_TCP = 6
#NET_FW_ACTION_ALLOW = 1
Name$ = "Per_InterfaceType_Rule"
Description$ = "Allow incoming network traffic over port 2400 coming from LAN interface type"
LocalPorts$ = Str(2400)
Interfacetypes$ = "LAN"
Grouping$ = "@firewallapi.dll,-23255"
IP_PROTOCOL_TCP$ = Str(#NET_FW_IP_PROTOCOL_TCP)
ACTION_ALLOW$ = Str(#NET_FW_ACTION_ALLOW)
fwPolicy2 = COMate_CreateObject("HNetCfg.FwPolicy2")
RulesObject = fwPolicy2\GetObjectProperty("Rules()") ; INetFwRules object
fwPolicy2\Invoke("CurrentProfilesTypes(" + Str(@CurrentProfiles) + ")")
NewRule = COMate_CreateObject("HNetCfg.FWRule") ; INetFwRule object
NewRule\SetProperty("Name = '" + Name$ + "'")
NewRule\SetProperty("Description = '" + Description$ + "'")
NewRule\SetProperty("Protocol = '" + IP_PROTOCOL_TCP$ + "'")
NewRule\SetProperty("LocalPorts = '" + LocalPorts$ + "'")
NewRule\SetProperty("Interfacetypes = '" + Interfacetypes$ + "'")
NewRule\SetProperty("Enabled = #True")
NewRule\SetProperty("Grouping = '" + Grouping$ + "'")
NewRule\SetProperty("Profiles = " + Str(@CurrentProfiles) + ")")
NewRule\SetProperty("Action = '" + ACTION_ALLOW$ + "'")
RulesObject\GetIntegerProperty("Add(" + Str(NewRule) + " as COMateobject)")
NewRule\Release()
RulesObject\Release()
fwPolicy2\Release()
EndProcedure
You sure about the @ in the line ?
That doesn't make sense from where I'm standing -or slobbing on the sofa!
Code: Select all
NewRule\SetProperty("Profiles = " + Str(@CurrentProfiles) + ")")That doesn't make sense from where I'm standing -or slobbing on the sofa!
I may look like a mule, but I'm not a complete ass.
DoH! I was stupid, This line doesn't really work (and besides it is not really needed it turns out) > "fwPolicy2\Invoke("CurrentProfilesTypes(" + str(@profileTypesBitmask) + " BYREF)")" < it doesn't return a pointer like thought. It creates the rule but doesn't put it in the correct profile, so everything was correct for the rule except the profile and because it created the rule properly and I didn't notice the profile was wrong it means that the above line wasn't returning a pointer like thought. And you were right > NewRule\SetProperty("Profiles = " + Str(@CurrentProfiles) + ")") was not right either.
but it turns out this does work:
So I was reading into the msdn too deeply and kept thinking pointer to a buffer when it wasn't realy needed. Now everything with the rule is correct including the profile. Thank you very much for your help. 
but it turns out this does work:
Code: Select all
Procedure AdvFireWall_LanRuleAdd()
Define fwPolicy2.COMateObject
Define RulesObject.COMateObject
Define NewRule.COMateObject
Name$ = "Per_InterfaceType_Rule"
Description$ = "Allow incoming network traffic over port 2400 coming from LAN interface type"
LocalPorts$ = Str(2400)
Interfacetypes$ = "LAN"
Grouping$ = "@firewallapi.dll,-23255"
fwPolicy2 = COMate_CreateObject("HNetCfg.FwPolicy2")
RulesObject = fwPolicy2\GetObjectProperty("Rules()") ; INetFwRules object
CurrentProfile = fwPolicy2\GetIntegerProperty("CurrentProfileTypes()")
NewRule = COMate_CreateObject("HNetCfg.FWRule") ; INetFwRule object
NewRule\SetProperty("Name = '" + Name$ + "'")
NewRule\SetProperty("Description = '" + Description$ + "'")
NewRule\SetProperty("Protocol = '" + Str(#NET_FW_IP_PROTOCOL_TCP) + "'")
NewRule\SetProperty("LocalPorts = '" + LocalPorts$ + "'")
NewRule\SetProperty("Interfacetypes = '" + Interfacetypes$ + "'")
NewRule\SetProperty("Enabled = #True")
NewRule\SetProperty("Grouping = '" + Grouping$ + "'")
NewRule\SetProperty("Profiles = '" + Str(CurrentProfile) + "'")
NewRule\SetProperty("Action = '" + Str(#NET_FW_ACTION_ALLOW) + "'")
RulesObject\GetIntegerProperty("Add(" + Str(NewRule) + " as COMateobject)")
NewRule\Release()
RulesObject\Release()
fwPolicy2\Release()
EndProcedure
Last edited by SFSxOI on Sun Apr 05, 2009 8:13 pm, edited 1 time in total.
any Idee with Selection.Insert Shift:=xlToRight
How can i use this
in Comate?
Code: Select all
Selection.Insert Shift:=xlToRightSorry, the follow is to this Function, i write from Disphelper to
COMate.
The full source, you can see here
http://www.purebasic.fr/german/viewtopi ... 466#239466
regards from germany (Sorry for my little english :roll: )
COMate.
Code: Select all
Procedure InsertCell(ExcelObject.COMateObject,Range.s,Wert.b) ;Insert Cells and shift right or down with Wert 0 or 1
ExcelObject\Invoke("Range('"+Range+"')\Select")
Debug "InsertCell()1: " +COMate_GetLastErrorDescription()
;dhCallMethod(*obj, "Range(%T).Select",@Range)
If Wert=0
ExcelObject\SetProperty("Selection\Shift := "+Str(#xlToRight))
ExcelObject\Invoke("Selection\Insert")
;dhCallMethod(*obj,"Selection.Insert Shift:= %d",#xlToRight)
Debug "InsertCell()2: " +COMate_GetLastErrorDescription()
ElseIf Wert=1
ExcelObject\SetProperty("Selection\Shift := "+Str(#xlDown))
ExcelObject\Invoke("Selection\Insert")
;dhCallMethod(*obj,"Selection.Insert Shift:= %d",#xlDown)
Debug "InsertCell()3: "+COMate_GetLastErrorDescription()
EndIf
EndProcedurehttp://www.purebasic.fr/german/viewtopi ... 466#239466
regards from germany (Sorry for my little english :roll: )
Now its ok. Thank You
,
but i have found a Solution
but i have found a Solution
Code: Select all
Procedure InsertCell(ExcelObject.COMateObject,Range.s,Wert.b) ;Insert Cells and shift right or down with Wert 0 or 1
ExcelObject\Invoke("Range('"+Range+"')\Select")
If Wert=0
ExcelObject\Invoke("Selection\Insert("+Str(#xlToRight)+")")
ElseIf Wert=1
ExcelObject\Invoke("Selection\Insert("+Str(#xlDown)+")")
EndIf
EndProcedure
Procedure DeleteCell(ExcelObject.COMateObject,Range.s,Wert.b) ;Delete Cells and shift left Or up with Wert 0 or 1
ExcelObject\Invoke("Range('"+Range+"')\Select")
If Wert=0
ExcelObject\Invoke("Selection\Delete("+Str(#xlToLeft)+")")
ElseIf Wert=1
ExcelObject\Invoke("Selection\Delete("+Str(#xlUp)+")")
EndIf
EndProcedure


