 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Sat Mar 06, 2010 12:01 am Post subject: |
|
|
AutoHotkey_COM: COM Error handling through ComError object is added.
| Code: | | ComObjConnect("ComError" [, function_name]) |
1) Omitting or passing non-existent/invalid function name will turn off the error handling, otherwise, turn it on. It's defaultly off.
2) The function should have one parameter which will be assigned to the ComError object containing the information about an error. Although the error handling will assign only the first parameter, currently it'll not reject the function with more than one parameters as this function can be of multi-purpose.
3) The ComError object has the following properties: name, number, message, source, description, helpfile, helpcontext
See the example of the usage in the below. For those members who don't want to write his own error handling function, I also included in the zip ComError.ahk which is supposed to be used as a standard library. ComError()/ComError("") will turn the error notification on/off.
| Code: | ComObjConnect("ComError", "ErrMsg")
...
ErrMsg(err)
{
MsgBox 0, 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
}
|
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu Apr 01, 2010 11:58 am Post subject: |
|
|
| AutoHotkey_COM: AutoHotkeySC.bin needed to compile a script is also added in the pack. |
|
| Back to top |
|
 |
Jabobian Guest
|
Posted: Mon Apr 12, 2010 8:06 am Post subject: need help on getting value of Variants |
|
|
The COM works well on PropertyGet and PropertyPut, however in some cases, a function to be invoked has some variables in its parameter list.
In the following example, dwgWidth and dwgHeight are double variables I want to get. Such variables can be simply "Dim"ed in VBA, but I don't know how to define them in ahk.
#Include Com.ahk
COM_Init()
swApp := COM_GetActiveObject("SldWorks.Application")
swDwgDoc := swApp.ActiveDoc()
dwgSize := swDwgDoc.GetCurrentSheet.GetSize(dwgWidth, dwgHeight)
MsgBox % "W" . dwgWidth * 1000 . "H" . dwgHeight * 1000 . "." & dwgSize
COM_Release(swApp)
COM_Term()
I tried various approach, for example
dwgWidth := COM_CreateObject("COM.VT_R8")
but the program will show an error:
Unmatched type, 0x80020005
Your help will be appreciated. |
|
| Back to top |
|
 |
Mahadir
Joined: 12 Apr 2010 Posts: 1 Location: Malaysia
|
Posted: Mon Apr 12, 2010 9:32 am Post subject: need help.. |
|
|
I dont understand how to use COM.. I hope someone can write an example using VB and calling it using Autohotkey.
 |
|
| Back to top |
|
 |
jabobian Guest
|
Posted: Mon Apr 12, 2010 12:47 pm Post subject: |
|
|
In addition to my previous post, here is the method description from the Solidworks API document.
Description
This method gets the size of the sheet and the corresponding standard sheet size.
Syntax (OLE Automation)
Size = Sheet.GetSize ( Width, Height)
Output: (double) Width Width of sheet
Output: (double) Height Height of sheet
Output: (long) Size Paper size as defined in swDwgPaperSizes_e
Syntax (COM)
status = Sheet->GetSize ( &Width, &Height, &Size)
Output: (double) Width Width of sheet
Output: (double) Height Height of sheet
Output: (long) Size Paper size as defined in swDwgPaperSizes_e
Return: (HRESULT) status
S_OK if successful |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Mon Apr 12, 2010 3:50 pm Post subject: |
|
|
| Which version of AHK/COM are you using? BTW, if you'd like to ask a question anonymously you'd get a better chance to be answered posting in Ask for Help section. |
|
| Back to top |
|
 |
Jabobian Guest
|
Posted: Tue Apr 13, 2010 4:49 am Post subject: |
|
|
Thanks for quick reply.
The AHK version is AutoHotKey_Lw 1, 0, 48, 05 (Unicode version)
The COM version is COM L version, created on 2009/12/17, 9:02:12.
I will try Ansi versions of AutoHotKey and COM to see if it works. Thanks |
|
| Back to top |
|
 |
jabobian
Joined: 13 Apr 2010 Posts: 29
|
Posted: Tue Apr 13, 2010 7:36 am Post subject: |
|
|
I tried the default version of AutoHotkey and COM, but still can not get it to work.
| Code: |
#Include D:\Program Files\AutoHotkey\Com.ahk
COM_Init()
COM_Error(1)
swApp := COM_GetActiveObject("SldWorks.Application")
swDwgDoc := COM_Invoke(swApp, "ActiveDoc")
currentSheet := COM_Invoke(swDwgDoc,"GetCurrentSheet")
dwgSize := COM_Invoke(currentSheet,"GetSize",dwgWidth, dwgHeight) ; or use "+" . dwgWidth, but neither works
prop := COM_Invoke(currentSheet,"GetProperties") ; this function works, but the returned value is an integer, not like an address pointer to an object.
COM_Release(swApp)
Com_Term() |
For your reference, the following is excerpted from the API document of Sheet.GetProperties ()
| Code: | Sheet::GetProperties
Description:This method gets the properties for this sheet object.
Syntax (OLE Automation)
retval = Sheet.GetProperties ()
Return: (VARIANT) retval VARIANT of type SafeArray (see Remarks)
Syntax (COM)
status = Sheet->IGetProperties ( retval )
Output: (double*) retval Pointer to an array of doubles (see Remarks)
Return:
(HRESULT)status S_OK if successful
Remarks
The return value is the following array of seven doubles:
[ paperSize, templateIn, scale1, scale2, firstAngle, width, height ] |
It seems to me, in the COM_Invoke function, only already known values are accepted in the parameter list. And the returned variable is limited to integer and string. I am totally lost. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Apr 13, 2010 9:38 am Post subject: |
|
|
You misunderstood my last message. Anyway, the object uses ByRef parameters, which is rarely found. Assuming you're using UNICODE build of AHK_L/COM_L, the code should be:
| Code: | swApp := COM_GetActiveObject("SldWorks.Application")
VarSetCapacity(dwgWidth, 8, 0)
VarSetCapacity(dwgHeight, 8, 0)
dwgSize := swApp.ActiveDoc.GetCurrentSheet.GetSize(COM_Parameter(0x4005, &dwgWidth), COM_Parameter(0x4005, &dwgHeight))
dwgWidth := NumGet(dwgWidth, 0, "double")
dwgHeight := NumGet(dwgHeight, 0, "double")
MsgBox % "W" . dwgWidth * 1000 . "H" . dwgHeight * 1000 . "." . dwgSize
|
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu Apr 15, 2010 10:40 am Post subject: |
|
|
AutoHotkey_COM: As VS 2010 is now RTMed, the executables are (re)compiled with VC++ 2010 Express. While at it, the ComError notification fell back to the old as with COM.ahk.
| Code: | | ComObjError( 0/1 ) ; turn the notification off/on. Defaultly on. |
|
|
| Back to top |
|
 |
jabobian
Joined: 13 Apr 2010 Posts: 29
|
Posted: Sun Apr 18, 2010 3:59 am Post subject: |
|
|
| Sean, Many thanks for your kind help, It works well! |
|
| Back to top |
|
 |
Boscolio
Joined: 18 Aug 2009 Posts: 8
|
Posted: Wed May 19, 2010 9:03 pm Post subject: Over my head |
|
|
Okay... I need some help.
I'm attempting to use a COM library that has a function who's parameter is a reference to an ANSI String. Frankly, it's a little out of my league unless I'm using VB and all the complexity is hidden.
The piece of code that I've got the trouble with is as follows:
| Code: | GW:=COM_CreateObject("GroupwiseCommander")
sRet:=COM_Invoke(GW,"Execute","EnvTextCurrentWord()",sResult) |
This is attempting to get the currently selected word in a Groupwise e-mail message (more details about EnvTextCurrentWord here).
sResult is the ANSI String that the function will place the result in.
I imagine that I'll need to use one or more of the string commands (such as COM_SysAllocString), but I haven't any idea how. Can someone enlighten me?
Thanks a lot! |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu May 20, 2010 12:11 am Post subject: Re: Over my head |
|
|
| Boscolio wrote: | | sResult is the ANSI String that the function will place the result in.! | ANSI string? I'm a little dubious about the documentation. Anyway, you may try this:
| Code: | sResult := "" ; must be in Global scope!
GW := COM_CreateObject("GroupwiseCommander")
sRet := COM_Invoke_(GW, "Execute", 8, "EnvTextCurrentWord()", 0x4008, "sResult")
|
|
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Thu May 20, 2010 8:19 am Post subject: |
|
|
I added COM support to AutoHotkey64 recently posted by fincs. It was compiled using VC++ 2010. The zip file contains both 32bit/64bit executables, modified/new source files, and VC++ 2010 project files.
DOWNLOAD: Go and get AutoHotkey64.
Last edited by Sean on Sat May 22, 2010 2:32 pm; edited 1 time in total |
|
| Back to top |
|
 |
fincs
Joined: 05 May 2007 Posts: 1163 Location: Seville, Spain
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|