AutoHotkey Community

It is currently May 26th, 2012, 9:54 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 646 posts ]  Go to page Previous  1 ... 12, 13, 14, 15, 16, 17, 18 ... 44  Next
Author Message
 Post subject:
PostPosted: October 4th, 2008, 11:50 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Now the variable COM_VT is Global in COM_Invoke()/COM_Invoke_(), which is the VT value of the result of COM_Invoke()/COM_Invoke_().


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2008, 7:05 am 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
Sean wrote:
Now the variable COM_VT is Global in COM_Invoke()/COM_Invoke_(), which is the VT value of the result of COM_Invoke()/COM_Invoke_().

Thank you for a very rapid reply. You are the true AHK Messiah.
Here's how I implemented COM_VT:
Code:
vValue := COM_Invoke(COM_Invoke(oRecordset, "Fields", sFieldName),"Value")
if (COM_VT=1) {   ; null
   Return ""      ; AHK null ;)
} Else {
   Return vValue
}

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Debugging
PostPosted: October 6th, 2008, 11:26 am 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
POST UPDATE: Now I ended up using plain ErrorLevel variable. It's quite easy to implement inside COM lib.
In the main script:
Code:
COM_Invoke(oObject,"SomeMethod")
if ErrorLevel
  Return



Old post:
The COM_Error function is magnificent. However, I tweaked it's error handling a bit.
After every unstable invoke call COM_IsError() could be called and process interrupted on failure.
I haven't tested it yet, though...

Alternatively just one global error variable could be used, like COM_VT. Then COM_IsError() and COM_SetError() wouldn't be needed. What do you think?

In the main script:
Code:
COM_Invoke(oObject,"SomeMethod")
if (COM_IsError()) {
  msgbox fail!
  return
}
; COM call was successful, continue processing



Here are the complete changes inside COM lib:
Code:
; Modified the old function
COM_Invoke( [params unchanged] ) ]
{
  COM_SetError(false) ; reset

  [... Old COM_Invoke code ...]
}

; Private
COM_SetError(bIsError)
{
  global COM_IsErrorVar
  COM_IsErrorVar := bIsError
}

; Public
COM_IsError()
{
  global COM_IsErrorVar
  return COM_IsErrorVar
}

; Modified the old function
COM_Error( [unchanged params] )
{
  [... Old COM_Error code ...]

  COM_SetError(true)
}

_________________
I recommend AutoIt instead of AHK.


Last edited by amokoura on October 7th, 2008, 6:50 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging
PostPosted: October 6th, 2008, 12:49 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
amokoura wrote:
After every unstable invoke call COM_IsError() could be called and process interrupted on failure.

You can use extended MsgBox syntax and IfMsgBox for that.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Debugging
PostPosted: October 6th, 2008, 1:30 pm 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
Sean wrote:
amokoura wrote:
After every unstable invoke call COM_IsError() could be called and process interrupted on failure.

You can use extended MsgBox syntax and IfMsgBox for that.


Sometimes I don't want to show a msgbox, passing the error forward is more useful in those cases. At least for me.

One nice "hack" to take the error handling to the next level would be setting a custom COM error handler. In the main script beginning:
COM_SetErrorHandler("myCustomHandler")
And when COM Error happens, myCustomHandler function will be called. It would receive detailed error data from COM_Error() and handle it in a custom way.

But for me, simple information, "Error happened yes/no?", is enough. And without msgboxes.

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2008, 2:20 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
amokoura wrote:
And when COM Error happens, myCustomHandler function will be called. It would receive detailed error data from COM_Error() and handle it in a custom way.
If COM had been built into AHK, I would have taken that route. Anyway, it's just a script, so you can tweak it to your need in your custom build.

Quote:
But for me, simple information, "Error happened yes/no?", is enough. And without msgboxes.

The above and this defeat the purpose of COM_Error. It's mainly to help beginners of COM to create/debug the scripts utilizing COM, and that's why default error notification had been switched to ON, which may appear intrusive. I often got the feeling that an user was even unaware of who produced the error MsgBox, AHK itself or COM.ahk.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 6th, 2008, 9:43 pm 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
Sean wrote:
...
so you can tweak it to your need in your custom build.
...
I often got the feeling that an user was even unaware of who produced the error MsgBox, AHK itself or COM.ahk.

Using complex COM is a challenge for basic AHK users, I understand. The msgbox error handling seems proper for them, for starters.
Luckily it's not a big deal to customize the script!

BTW I chose the path of a global error variable and got rid of the helper error functions that I mentioned before.

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Errorlevel
PostPosted: October 10th, 2008, 11:28 am 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
I've used COM lib with errorlevels and experiences are quite positive.

I recommend these additions:
- COM_Invoke resets ErrorLevel to zero
- on COM_Error, set ErrorLevel to 1

Just couple lines to add. It's backwards compatible, because ignoring the errorlevel causes the old behaviour: script continues.

Errorlevel is an AHK-native thing so the logic wouldn't disturb new users.

I'm not requiring this change to the official source. Just tips for tweakers!

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 12:10 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
i dun like adding un necesary lines to invoke i mean a usefull null variable is one thing but there is no need for errorlevel as far as im concerned

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 1:30 pm 
Offline

Joined: November 14th, 2006, 7:49 pm
Posts: 15
tank wrote:
...there is no need for errorlevel as far as im concerned

You told earlier you're using ADO. Aren't the connection/query calls unreliable enough to require some error checking?

_________________
I recommend AutoIt instead of AHK.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 10th, 2008, 11:05 pm 
Offline
User avatar

Joined: December 21st, 2007, 3:14 pm
Posts: 3826
Location: Louisville KY USA
amokoura wrote:
tank wrote:
...there is no need for errorlevel as far as im concerned

You told earlier you're using ADO. Aren't the connection/query calls unreliable enough to require some error checking?
there is no benifit i can see outside of the exisitn COM_Error(1) functionality to using errorlevel from ahk

_________________
No matter what your oppinion Please join this discussion
Formal request to Polyethene
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 13th, 2008, 3:21 pm 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
Hi Sean


1.
COM ahk

is it posssible to wrap ahk script as COM activex dll object ?
if yes how it can be done ?

2. how I can make COM object Instance (once)
so other tasks (threads) can 'see' this instance
and use it's methods and properties ?
without making new COM object instance on every task ?
I think MS calls it DCOM ? (distributed COM)

have some code sample how to do it or link ?

rgrds
rani


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 12:06 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
rani wrote:
is it posssible to wrap ahk script as COM activex dll object ?
You can wrap it in exe COM Server:
http://www.autohotkey.com/forum/topic25746-36.html

Quote:
without making new COM object instance on every task ?
That depends on the COM Server itself and/or you can keep the table of objects yourself.

Quote:
I think MS calls it DCOM ? (distributed COM)
It's for Remote COM Servers.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 5:10 am 
Offline

Joined: March 18th, 2008, 4:04 am
Posts: 193
can you link on sample code
how to access COM objects that where instanced in some task ?

so I can copy it and use it , with my adjustments.

rgrds

rani


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: October 14th, 2008, 10:09 am 
Offline

Joined: October 10th, 2008, 1:32 pm
Posts: 4
I am trying to use COM to access some information from Active Directory.

So far, I have this working to pull information out:
Code:
#include COM.ahk
COM_Init()

; Administrator credentials to bind to the Domain
; Only need if user does not logon as admiistrator
AdminID := "Admin22"
AdminPass := "Password"

; Domain that the information needs to be pulled from.
; Can be an empty string if the computer that this program
; is run from is part of the domain.
DomainString := "domain.com"

; Subdomain that the account is located in.
SubDomainString := "subdomain"

; ID to search for in the domain.
IDString := "smithj"

; Connect to the domain controller
objDSO := COM_GetObject("WinNT:")

; Compose search string
UserSearchString := "WinNT://" . SubDomainString
If (DomainString <> "")
   UserSearchString .= "." . DomainString
UserSearchString .= "/" . IDString . ",User"

; Long delay while connecting to this object
objUser := COM_Invoke(objDSO, "OpenDSObject", UserSearchString , AdminID , AdminPass , 3) ; ADS_SECURE_AUTHENTICATION | ADS_USE_ENCRYPTION

; Get account name
FullName := COM_Invoke(objUser, "FullName")

; Check for expired password
If (COM_Invoke(objUser, "Get", "PasswordExpired"))
   PasswordExpired := "True"
Else
   PasswordExpired := "False"
   
Rslt := "Full Name: " . FullName . "`n"
Rslt .= "Password Expired: " . PasswordExpired . "`n"

MsgBox , %Rslt%

; Release com objects and close app
COM_Release(objUser)
COM_Release(objDSO)
COM_Term()
ExitApp



There is lots of other information that I can get using this, however I cannot figure out how to get the group information.

In Visual Basic, this should provide a list of the groups but I cannot figure out how to convert it to AutoHotkey:
Code:
; Creates the list of goups the user belongs To
For $objGroup In $objUser.Groups      
   $Groups = $Groups & $objGroup.Name & ","
Next



The syntax is: http://msdn.microsoft.com/en-us/library/aa746342(VS.85).aspx

Code:
HRESULT Groups(
  [out]  IADsMembers **ppGroups
);



I am assuming it translates to something like:
Code:
objGL := COM_Invoke_(objUser, "Groups", "UInt", &*ppGroups)



But how do I read the information?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 646 posts ]  Go to page Previous  1 ... 12, 13, 14, 15, 16, 17, 18 ... 44  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 18 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group