AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COM Standard Library
Goto page Previous  1, 2, 3 ... 36, 37, 38 ... 42, 43, 44  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Mon Feb 22, 2010 12:01 am    Post subject: Reply with quote

You can redistribute COM.ahk, preferably as it is.
Back to top
View user's profile Send private message
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Mon Feb 22, 2010 5:35 pm    Post subject: Reply with quote

Hey Sean,

I'm trying to rewrite some functions to work with AHK_L and after several attempts and conulting with jethrow, I'm stuck. Can you create a call to COM_Invoke in COM_L combined with ternary? This is the line I'm trying to translate:

Code:
res:=COM_Invoke(pWin,"document.all.tags[table].item[" t "]"
     . ((row < 0) ? ".rows" : "rows[" r "].cells")
     . ".length")


I'm having absolutely zero luck making something that will produce a result. I tried this:

Code:
pWin["document.all.tags[table].item[" t "]" (( row<0 ) ? "rows" : "rows[" r "].cells" ) ".length"]


That produces no errors but also no result. I also tried this (at jethrow's somewhat suggestion):

Code:
pWin.document.all.tags("table").item[t] ((row < 0) ? .rows : .rows[r].cells) .length


But again no luck. Am I missing something in how the syntax is implemented or is ternary not possible in the new implmentation?
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Lexikos



Joined: 17 Oct 2006
Posts: 7299
Location: Australia

PostPosted: Mon Feb 22, 2010 9:51 pm    Post subject: Reply with quote

When I run your second code, I get this message:
Quote:
COM Error Notification
---------------------------
Function Name: "item[1]rows.length."
ERROR: No COM Dispatch Object!
()
It's missing a dot. However, I got "no errors but also no result" at first because I was using GetWebBrowser() and wasn't calling COM_Init(). It's only called automatically by COM_CreateObject().

Your third code has a syntax error. When you write ] (, it is implicitly concatenation; i.e.
Code:
pWin.document.all.tags("table").item[t] . ((row < 0) ? .rows : .rows[r].cells) .length
I suppose there are two ways:
Code:
table := pWin.document.all.tags("table").item[t]
MsgBox % r < 0 ? table.rows.length : table.rows[r].cells.length
Code:
MsgBox % pWin.document.all.tags("table").item[t][(r < 0) ? "rows.length" :  "rows[" r "].cells.length"]
I didn't know what the usage of 'row' vs 'r' was, so I used 'r' in both. I think that passing the entire COM expression in a string via [] or COM_Invoke() is actually more efficient, as it doesn't need to wrap each intermediate COM object in an AHKL object.
Back to top
View user's profile Send private message Visit poster's website
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Mon Feb 22, 2010 11:36 pm    Post subject: Reply with quote

Sorry for the confusion Lexikos, that snippet of code is being used inside a function. Probably no sooner than I had figured that out on my own, you had posted it. So that I have working, but I still have a problem. I'm trying to retrieve a type of data from a table cell on a website, but I need to keep the type optional in the COM call. For example this:

Code:
COM_Invoke(pwb,"document.all[q].innerText")


Would be like this:

Code:
type:="innerText"

COM_Invoke(pwb,"document.all[q]." type)


And the above works. So if I want to pull data from a cell on the forum main page (using iWeb_getWin to obtain the window handle), the code would look something like this:

Code:
type:="innerText"
pwb:=iWeb_getWin("AutoHotkey Community - Mouse and Keyboard Macros and Hotkeys")
MsgBox % pwb.document.all.tags[table].item[4].rows[2].cells[1].(type)


But that produces nothing. How would I pass the type in the call the same way I pass it in the 'traditional' call?
_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Tue Feb 23, 2010 12:02 am    Post subject: Reply with quote

sinkfaze wrote:
Code:
type:="innerText"
pwb:=iWeb_getWin("AutoHotkey Community - Mouse and Keyboard Macros and Hotkeys")
MsgBox % pwb.document.all.tags[table].item[4].rows[2].cells[1].(type)
Which build of AHK_L are you using? This code should produce a syntax error in older builds, and no syntax error with the latest build but I suppose the last call will be effectively COM_Release(). Use:
Code:
MsgBox % pwb.document.all.tags[table].item[4].rows[2].cells[1][type]
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7299
Location: Australia

PostPosted: Tue Feb 23, 2010 9:04 am    Post subject: Reply with quote

sinkfaze wrote:
MsgBox % pwb.document.all.tags[table].item[4].rows[2].cells[1].(type)
If the documentation is inadequate, I am open to suggestions...

FYI, obj[anything] should be equivalent to COM_Invoke(obj,anything). Using [] indirectly calls COM_Invoke, but you can still call it directly with COM_L. However, I think that including the "dotted expression" in a string isn't supported in AutoHotkey_COM, and I don't intend to change this when I integrate it into AHKL.
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Tue Feb 23, 2010 1:07 pm    Post subject: Reply with quote

Lexikos wrote:
However, I think that including the "dotted expression" in a string isn't supported in AutoHotkey_COM, and I don't intend to change this when I integrate it into AHKL.
BTW, I think I got completely wrong about aResultToken.marker of SYM_STRING. What allocator/deallocator (:seems to be malloc/free?) should I use to pass the result string? I directly passed the resultant BSTR's (and freed them shortly after), and it worked so far by pure chance, due to the caching of BSTR's by COM.
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7299
Location: Australia

PostPosted: Tue Feb 23, 2010 10:02 pm    Post subject: Reply with quote

Sean wrote:
What allocator/deallocator (:seems to be malloc/free?) should I use to pass the result string?
Use TokenSetResult. If the string is <=MAX_NUMBER_LENGTH it uses a stack-allocated buffer which is passed to built-in functions via aResultToken.buf, so you must make sure that hasn't been overwritten. Otherwise it uses malloc and returns it via aResultToken.circuit_token and its length via aResultToken.buf. aResultToken.marker is set in both cases, but circuit_token tells ExpandExpression that malloc was used, and to free the memory later.
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Wed Feb 24, 2010 9:37 am    Post subject: Reply with quote

Lexikos wrote:
Use TokenSetResult.
Thanks, now I changed to use it.

AutoHotkey_COM Update: A new function ComObjType is added.

Code:
; ComObjType(ComObj, "name" / "iid")

obj := ComObjCreate("htmlfile")
MsgBox % ComObjType(obj, "name") " : " ComObjType(obj, "iid")
Back to top
View user's profile Send private message
ahk_beginner1281
Guest





PostPosted: Thu Feb 25, 2010 12:44 pm    Post subject: Reply with quote

Hello AHK Community,

i'm searching a way to comunicate with my tool virtual dj.
On the plugin devloper site http://www.virtualdj.com/wiki/Developers.html stands,

"Plugins in VirtualDJ look a lot like COM objects, so any languages that can create COM objects can create a plugin for VirtualDJ (Visual Basic, C#, etc).
Still, we highly recommend to use C++, since that's the native language of the header files, and that's also the language in which you'll find all the help on the forums here."

But how can i communicate to the program over ahk?

On the SDK Site i have found a C++ Header file. That can be found on http://www.virtualdj.com/developers/vdjPlugin.h

I have seen in 2 Main mehtods to communicate and become callbacks

Code:

// callback functions to communicate with VirtualDJ
HRESULT (VDJ_API *SendCommand)(char *command,int deck); // send a command to VirtualDJ
HRESULT (VDJ_API *GetInfo)(char *query,void *result); // get infos from VirtualDJ


Is it possible to comunicatw over the ahk com.ahk to virtual dj?

Thx for your help
Back to top
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Thu Mar 04, 2010 4:27 pm    Post subject: Reply with quote

Sean wrote:
And, although I also implemented COM error handling through a new ComError Object which is a singleton, I didn't include it either as, telling from the past experiences, most users didn't care about the error messages, even the error itself. If it's desirable, however, I'll include it.

... The concern is that we must keep minimal the size of newly added codes, otherwise, AHK can be easily bloated. So, codes which will be rarely used by few members better not be included. Nevertheless, as the error handling is very important I'll think about it again.

Just a thought, but how about having COM Error messages available throught the COM library. Then calling COM_Error(1) could turn this functionallity on. This shouldn't be too much trouble for users who know about & use the error messages.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Thu Mar 04, 2010 4:43 pm    Post subject: Reply with quote

if im not mistaken jethrow thats already the case
i commonly turn errors on and off within scripts
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Thu Mar 04, 2010 4:52 pm    Post subject: Reply with quote

I suppose I should clarify. I mean with AutoHotkey_COM, which currently doesn't display COM Error messages. We discussed this back on page 35. I tried putting COM_Error( 1 ) at the beginning of my script, but with AutoHotkey_COM, the COM Error message still doesn't display.
_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
tank



Joined: 21 Dec 2007
Posts: 3700
Location: Louisville KY USA

PostPosted: Thu Mar 04, 2010 4:58 pm    Post subject: Reply with quote

ah i see i didnt realise you were speaking of the ahk_com.exe
by sean
_________________

We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 2462

PostPosted: Fri Mar 05, 2010 12:08 am    Post subject: Reply with quote

I haven't decided yet whether to include it or not. As you have to explicitly enable the error notification, through ComObjConnect(func_name), and write the error handling function yourself, I'm a little dubious about the usability of it, judging from the past experience on the average programming skills of the users in the forum.

For example, here is my own implementation. Err()/Err("") will turn on/off the error notification.
Code:
; ERR.ahk in lib subdirectory
err(err="err")
{
   if not   IsObject(err)
   return   ComObjConnect(err)
   MsgBox   4, COM Error, % "Name:`t" err.Name "`n" err.Number ":`t" err.Message "`nSource:`t" err.Source "`nDescription:`t" err.Description "`nHelp:`t" err.HelpFile "," err.HelpContext
   IfMsgBox  Yes,   ExitApp
}


jethrow wrote:
Just a thought, but how about having COM Error messages available throught the COM library. Then calling COM_Error(1) could turn this functionallity on. This shouldn't be too much trouble for users who know about & use the error messages.
That can be done, but you still have to have included the function already in the script, via any means, and the function name and its parameters should be aleady-agreed ones, possibly ComError(name, hr, pei) (:I don't think COM_Error is a good candidate and currently it can be leaking memory when error notification is turned off).
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3 ... 36, 37, 38 ... 42, 43, 44  Next
Page 37 of 44

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group