AutoHotkey Community

It is currently May 27th, 2012, 4:56 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 646 posts ]  Go to page Previous  1 ... 35, 36, 37, 38, 39, 40, 41 ... 44  Next
Author Message
 Post subject:
PostPosted: March 6th, 2010, 1:01 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 1st, 2010, 12:58 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
AutoHotkey_COM: AutoHotkeySC.bin needed to compile a script is also added in the pack.


Report this post
Top
 Profile  
Reply with quote  
PostPosted: April 12th, 2010, 9:06 am 
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.


Report this post
Top
  
Reply with quote  
 Post subject: need help..
PostPosted: April 12th, 2010, 10:32 am 
Offline

Joined: April 12th, 2010, 10:05 am
Posts: 1
Location: Malaysia
I dont understand how to use COM.. I hope someone can write an example using VB and calling it using Autohotkey.

:(


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2010, 1:47 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 12th, 2010, 4:50 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 5:49 am 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 8:36 am 
Offline

Joined: April 13th, 2010, 8:05 am
Posts: 29
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 13th, 2010, 10:38 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2010, 11:40 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 18th, 2010, 4:59 am 
Offline

Joined: April 13th, 2010, 8:05 am
Posts: 29
Sean, Many thanks for your kind help, It works well!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Over my head
PostPosted: May 19th, 2010, 10:03 pm 
Offline

Joined: August 18th, 2009, 6:04 pm
Posts: 10
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: Over my head
PostPosted: May 20th, 2010, 1:11 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2010, 9:19 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
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 May 22nd, 2010, 3:32 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 20th, 2010, 2:51 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Great!
How did you manage to compile for 64-bit using VC++ 2010?

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


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 ... 35, 36, 37, 38, 39, 40, 41 ... 44  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 10 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