 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Dewi Morgan
Joined: 03 Oct 2005 Posts: 186
|
Posted: Thu Jun 28, 2007 6:48 am Post subject: |
|
|
I'm confident that I for one would use easycom :) _________________ Yet another hotkeyer. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Jun 29, 2007 4:51 am Post subject: |
|
|
| tfcahm wrote: | | If you want to keep going, I'll do whatever I can to help you help me. I respect you not wanting to install the app. It is probably very difficult to go forward without it, but I'll try anything here to get you useful feedback. I'd really like to get this working. If you are done with it that's okay too. |
As I officially added dispatch type invoking in CoHelper.ahk, I rewrote the previous script using it.
So, retry and see how it's going.
| Code: | #Include CoHelper.ahk
CoInitialize()
pds := ActiveXObject("BookCAT.DataServer")
sXSLTemplate := "BookList.xsl"
sFilter := "Author=John Grisham"
sFilename := ""
sRecordset := ""
bStripLinks := False
pXSLTemplate := SysAllocString(sXSLTemplate)
pFilter := SysAllocString(sFilter)
pFilename := SysAllocString(sFilename)
pRecordset := SysAllocString(sRecordset)
VarSetCapacity(var, 88, 0)
NumPut(8|0x4000, var, 0), NumPut(&var+80, var, 8)
NumPut(8|0x4000, var,16), NumPut(&var+84 ,var,24)
NumPut(11,var, 32), NumPut(-bStripLinks, var, 40, "short")
NumPut(8, var, 48), NumPut(pFilter , var, 56)
NumPut(8, var, 64), NumPut(pXSLTemplate, var, 72)
NumPut(pRecordset, var, 80), NumPut(pFilename, var, 84)
nResult := Invoke(pds, "GenerateHTML", var)
Unicode2Ansi(pstr1 := NumGet(var, 80), sRecordset)
Unicode2Ansi(pstr2 := NumGet(var, 84), sFilename)
SysFreeString(pXSLTemplate)
SysFreeString(pFilter)
SysFreeString(pFilename)
SysFreeString(pRecordset)
Release(pds)
CoUninitialize()
MsgBox, % "GenerateHtml`n Filename: " . sFilename . "`n Recordset: " . sRecordset
|
PS. Need the latest CoHelper.ahk which in turn requires the AHK build 1.0.47.00 or above. |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Fri Jun 29, 2007 5:21 am Post subject: |
|
|
| Quote: | As I officially added dispatch type invoking in CoHelper.ahk, I rewrote the previous script using it.
So, retry and see how it's going.
| Oh sweetness! That works great. I need to spend some time studying your code to understand how to use Invoke, but wanted to report right away that it is working properly.
Thanks Sean! I really appreciate your work and the help you given. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Jun 29, 2007 7:05 am Post subject: |
|
|
| tfcahm wrote: | | That works great. I need to spend some time studying your code to understand how to use Invoke, but wanted to report right away that it is working properly. |
Glad to hear that it's working well.
BTW, I think it confirms my previous suspicion that there may be some glitch in BookCat's COM implementation. |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Fri Jun 29, 2007 7:12 pm Post subject: |
|
|
| Quote: | | Glad to hear that it's working well. | Except for these two, I've got all the other methods working now. They both seem to do nothing and generate no errors. Maybe with a hint on either one I can figure them both out. It must be something wrong in how I've constructed var. Can you see anything obvious that is not correct? Thanks again. | Code: | ;ChangeSortOrder
pFilename := SysAllocString("")
pOrderBy := SysAllocString("title")
pRecordset := SysAllocString(sRecordset) ;input value comes from GenerateHTML
VarSetCapacity(var, 56, 0)
NumPut(8|0x4000, var, 0), NumPut(&var+48, var, 8)
NumPut(8,var, 16), NumPut(pOrderBy, var, 24)
NumPut(8|0x4000, var, 32), NumPut(&var+52, var, 40)
NumPut(pFilename,var, 48), NumPut(pRecordset, var, 52)
nResult := Invoke(pds, "ChangeSortOrder", var)
Unicode2Ansi(pstr1 := NumGet(var, 48), sFilename)
Unicode2Ansi(pstr2 := NumGet(var, 52), sRecordset)
SysFreeString(pFilename)
SysFreeString(pRecordset)
SysFreeString(pOrderBy)
MsgBox, % "ChangeSortOrder`n Filename: " . sFilename . "`n New Recordset: " . sRecordset | and here's the type lib | Code: | ' ****************************************************************************************
' ChangeSortOrder method
' Interface name = IDataServer
' VTable offset = 64 [&H40]
' DispID = 209 [&H000000D1]
' ****************************************************************************************
FUNCTION BookCATIDataServer_ChangeSortOrder ALIAS "BookCATIDataServer_ChangeSortOrder" ( _
BYVAL pthis AS DWORD PTR _ ' %VT_DISPATCH <dispinterface>
, BYREF RecordsetGUID AS STRING _ ' *%VT_BSTR <DYNAMIC UNICODE STRING> [in]
, BYVAL OrderBy AS STRING _ ' %VT_BSTR <DYNAMIC UNICODE STRING> [in]
, BYREF prmFilename AS STRING _ ' *%VT_BSTR <DYNAMIC UNICODE STRING> [in]
, BYREF Result AS LONG _ ' *%VT_I4 <LONG> [out]
) EXPORT AS LONG ' %VT_HRESULT <LONG>
LOCAL HRESULT AS LONG
OrderBy = UCODE$(OrderBy)
IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
CALL DWORD @@pthis[16] USING BookCATIDataServer_ChangeSortOrder(pthis, RecordsetGUID, OrderBy, prmFilename, Result) TO HRESULT
FUNCTION = HRESULT
RecordsetGUID = ACODE$(RecordsetGUID)
prmFilename = ACODE$(prmFilename)
END FUNCTION |
And the other one | Code: | ;GenerateHTMLListPage
pFilename := SysAllocString("")
nPage := 2
pRecordset := SysAllocString(sRecordset) ;value comes from GenerateHTML with sFilter:="Author=*"
VarSetCapacity(var, 52, 0)
NumPut(8|0x4000, var, 0), NumPut(&var+48, var, 8)
NumPut(3,var, 16), NumPut(nPage, var, 24)
NumPut(8, var,32), NumPut(pRecordset ,var,40)
NumPut(pFilename, var, 48)
nResult := Invoke(pds, "GenerateHTMLListPage", var)
Unicode2Ansi(pstr1 := NumGet(var, 48), sFilenameOUT)
SysFreeString(pFilename)
SysFreeString(pRecordset)
MsgBox, % "GenerateHtmlListPage`n Filename: " . sFilenameOUT . "`n nResult: " . nResult |
| Code: | ' ****************************************************************************************
' GenerateHTMLListPage method
' Interface name = IDataServer
' VTable offset = 60 [&H3C]
' DispID = 208 [&H000000D0]
' ****************************************************************************************
FUNCTION BookCATIDataServer_GenerateHTMLListPage ALIAS "BookCATIDataServer_GenerateHTMLListPage" ( _
BYVAL pthis AS DWORD PTR _ ' %VT_DISPATCH <dispinterface>
, BYVAL RecordsetGUID AS STRING _ ' %VT_BSTR <DYNAMIC UNICODE STRING> [in]
, BYVAL PageNo AS LONG _ ' %VT_I4 <LONG> [in]
, BYREF prmFilename AS STRING _ ' *%VT_BSTR <DYNAMIC UNICODE STRING> [in]
, BYREF Result AS LONG _ ' *%VT_I4 <LONG> [out]
) EXPORT AS LONG ' %VT_HRESULT <LONG>
LOCAL HRESULT AS LONG
RecordsetGUID = UCODE$(RecordsetGUID)
IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
CALL DWORD @@pthis[15] USING BookCATIDataServer_GenerateHTMLListPage(pthis, RecordsetGUID, PageNo, prmFilename, Result) TO HRESULT
FUNCTION = HRESULT
prmFilename = ACODE$(prmFilename)
END FUNCTION |
| Quote: | | BTW, I think it confirms my previous suspicion that there may be some glitch in BookCat's COM implementation. | I accept your word on it. I'm too ignorant still about the inner workings of COM to know why it didn't work. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Fri Jun 29, 2007 11:49 pm Post subject: |
|
|
| tfcahm wrote: | | Except for these two, I've got all the other methods working now. They both seem to do nothing and generate no errors. Maybe with a hint on either one I can figure them both out. It must be something wrong in how I've constructed var. |
No, as far as I can see, you've done them right. Good job.
To make sure that it's not another glitch in BookCat side, did they work with other apps like Perl, on the contrary?
The only thing I can't be sure from here is sRecordset.
What value did you use for it? When/how did you obtain it?
One thing I'm suspecting about it atm is that it may not have a permanent meaning, only have a temporary meaning in that opened session.
What I mean is, if you obtained the value in the previously opened BookCat, then closed and restarted it, then the value would be useless in the new opened BookCat. |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Sat Jun 30, 2007 1:06 am Post subject: |
|
|
Everything does work properly in Perl. Since all the other methods are working now in AHK, I think there must be something just slightly wrong in my code.
sRecordset is generated immediately before either of these code segments runs by using your GenerateHTML code. The program flow in Perl and AHK is the same. To avoid multiple conversions I tried simply reusing pRecordset (of course without the SysFreeString) but that gave the same result.
In all cases sRecordset gets reused inside a single CoInitialize(), pds := ActiveXObject("BookCAT.DataServer") / Release(pds), CoUninitialize() and BookCAT always remains open. sRecordset is a pretty generic GUID, for example {86636F60-FAFB-4F7B-81A8-0BC0EDE2C5A4}.
I'm going to keep noodling over this. After coding all the other methods my eyes have glazed over so maybe a fresh look later will reveal something.
Thanks again for your help! |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Sat Jun 30, 2007 6:18 am Post subject: |
|
|
I got it! var has to be reinitialized each time before the structure is built. | Code: | | VarSetCapacity(var, 0) | Everything is working fine now with that addition.
Thanks again Sean, you've been a great help. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Sat Jun 30, 2007 5:06 pm Post subject: |
|
|
| tfcahm wrote: | | Everything is working fine now with that addition. |
Nice! Would you post the script in the forum?
It can be useful to some other users too directly, or indirectly as a good example to study/use COM. |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Sat Jun 30, 2007 10:31 pm Post subject: |
|
|
| Quote: | Nice! Would you post the script in the forum?
It can be useful to some other users too directly, or indirectly as a good example to study/use COM. | Will do once I get my app complete. The code I posted above is representative, however.
Right now I'm fighting a strange intermittant memory write error that appears right when the application script exits (that is after CoUninitialize). There's no obvious cause and the error is not yet controllably repeatable. So, I have some debugging still to go. |
|
| Back to top |
|
 |
FlowPEE
Joined: 28 Feb 2007 Posts: 14
|
Posted: Tue Jul 03, 2007 5:23 pm Post subject: |
|
|
Sean,
I managed to send keystrokes to Citrix finally!
The problem was, that one have to set first the property "Outputmode" to the value 1. So only then you have a valid session identifier and there you can attach with the keyboard.
I have another question regarding your invoke function.
Normally, you would do e.g.
| Code: | | pmouse := Invoke(pssn,"Mouse") |
to obtain the identifier for the mouse.
but how would I use the invoke function to send e.g. a mouseclick?
From typelib I have
| Code: |
' ****************************************************************************************
' SendMouseDown method
' Interface name = IMouse
' method SendMouseDown
' VTable offset = 28 [&H1C]
' DispID = 100 [&H00000064]
' ****************************************************************************************
FUNCTION CitrixIMouse_SendMouseDown ALIAS "CitrixIMouse_SendMouseDown" ( _
BYVAL pthis AS DWORD PTR _ ' %VT_DISPATCH <dispinterface>
, BYVAL buttonId AS LONG _ ' %VT_I4 <LONG> [in]
, BYVAL modifiers AS LONG _ ' %VT_I4 <LONG> [in]
, BYVAL XPos AS LONG _ ' %VT_I4 <LONG> [in]
, BYVAL YPos AS LONG _ ' %VT_I4 <LONG> [in]
) EXPORT AS LONG ' %VT_HRESULT <LONG>
LOCAL HRESULT AS LONG
IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
CALL DWORD @@pthis[7] USING CitrixIMouse_SendMouseDown(pthis, buttonId, modifiers, XPos, YPos) TO HRESULT
FUNCTION = HRESULT
END FUNCTION
' **************************************************************************************** |
My problem here is that I do not know how to pass more parameters to the invoke function.
I tried with | Code: | | Invoke(pmouse, "SendMouseDown", pbuttonId pmodifiers pXpos pYpos) | but that didn't work out.
Any help is appreciated
thanks Sean !
florian |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Tue Jul 03, 2007 11:34 pm Post subject: |
|
|
| FlowPEE wrote: | | My problem here is that I do not know how to pass more parameters to the invoke function. |
I updated CoHelper.ahk adding a function DispParams(Variable, type1, val1, type2, val2, ...) to allocate the parameters and a few other minor modifications, so, please recopy it.
Then try the following:
| Code: | | Invoke(pmouse, "SendMouseDown", DispParams(varg, 3, ButtonId, 3, Modifiers, 3, Xpos, 3, Ypos) ; VT_I4 = 3 |
Last edited by Sean on Thu Jul 05, 2007 1:28 am; edited 1 time in total |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Jul 04, 2007 12:42 am Post subject: |
|
|
There was a request about MSCOMM32.OCX.
Its interface is really simple: most of the functions expect 0 or 1 parameter.
So, the usage could be, using the latest CoHelper.ahk:
| Code: | #Include CoHelper.ahk
DISPATCH_PROPERTYPUT := 4
VT_I2 := 2
VT_I4 := 3
CoInitialize()
MsgBox, % pcomm := ActiveXObject("{648A5603-2C6E-101B-82B6-000000000014}")
; Get CommID
MsgBox, % nCommID := Invoke(pcomm, "CommID")
; Put CommID
Invoke(pcomm, "CommID", DispParams(varg, VT_I4, nCommID), DISPATCH_PROPERTYPUT)
; Get CommPort
MsgBox, % nCommPort := Invoke(pcomm, "CommPort")
; Put CommPort
Invoke(pcomm, "CommPort", DispParams(varg, VT_I2, nCommPort), DISPATCH_PROPERTYPUT)
Release(pcomm)
CoUninitialize()
|
Last edited by Sean on Thu Jul 05, 2007 1:29 am; edited 1 time in total |
|
| Back to top |
|
 |
tfcahm
Joined: 20 May 2007 Posts: 48
|
Posted: Wed Jul 04, 2007 1:55 am Post subject: |
|
|
| Quote: | | I updated CoHelper.ahk adding a function DispParams(no of parameters, Variable, type1, val1, type2, val2, ...) to allocate the parameters | I really like this. If you don't do it first, I'd like to extend it to handle BYREFs.
One question Sean, what is the purpose of the VarSetCapacity(varg, -1)? Doesn't the original VarSetCapacity get the size correct, or am I missing something?
I'm still battling a strange error with my app: | Code: | AutoHotkey.exe - Application Error
The instruction at "0x0005c215" referenced memory at "0x000dc938". The memory could not be "written". | I don't even know how to ask for help because it's been hard to isolate. What is consistent is that it happens when the AHK script exits (all the COM stuff in the script seems to function properly). The error shows on clean installs of WinXP SP1 and SP2, but not on Win2K. Strange. |
|
| Back to top |
|
 |
Sean
Joined: 12 Feb 2007 Posts: 2462
|
Posted: Wed Jul 04, 2007 2:43 am Post subject: |
|
|
| tfcahm wrote: | | Quote: | | I updated CoHelper.ahk adding a function DispParams(no of parameters, Variable, type1, val1, type2, val2, ...) to allocate the parameters | I really like this. If you don't do it first, I'd like to extend it to handle BYREFs. |
OK, I'd like to leave it to you.
| Quote: | | One question Sean, what is the purpose of the VarSetCapacity(varg, -1)? Doesn't the original VarSetCapacity get the size correct, or am I missing something? |
The purpose of it is to update the length (:not the capacity) as AHK doesn't do it automatically in this case.
It's needed here as otherwise the first byte of the allocated varg will be erased.
| Quote: | I'm still battling a strange error with my app: | Code: | AutoHotkey.exe - Application Error
The instruction at "0x0005c215" referenced memory at "0x000dc938". The memory could not be "written". | I don't even know how to ask for help because it's been hard to isolate. What is consistent is that it happens when the AHK script exits (all the COM stuff in the script seems to function properly). The error shows on clean installs of WinXP SP1 and SP2, but not on Win2K. Strange. |
I'm not sure if it's AHK's problem.
I'm suspecting that BookCat may have a bug to manage a buffer, as I think that the original script using the VTable interface would have worked already otherwise. |
|
| 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
|