AutoHotkey Community

It is currently May 25th, 2012, 6:32 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 156 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 11  Next
Author Message
 Post subject:
PostPosted: May 20th, 2007, 11:50 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tfcahm wrote:
The iTunes Create Folder method expects a Unicode string as input instead of a pointer to the string. Though it looks right to me, this code does not work.

Ansi2Unicode() is not enough in iTunes case as the COM server lives in another process.
Try this instead:

Code:
#NoEnv
#Include CoHelper.ahk
CoInitialize()
CLSID_iTunesApp := "{DC0C2640-1415-4644-875C-6F4D769839BA}"
 IID_IiTunes    := "{9DD6680B-3EDC-40DB-A771-E6FE4832E34A}"
piT := CreateObject(CLSID_iTunesApp, IID_IiTunes)

sFldr := "MyNewFldr"
pFldr := SysAllocString(sFldr)
DllCall(VTable(piT, 84), "Uint", piT, "Uint", pFldr, "UintP", pPlist)  ; Create Folder
SysFreeString(pFldr)

Release(piT)
CoUninitialize()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 21st, 2007, 3:36 am 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
That's perfect! Thanks Sean for your help now and all you've done developing the COM Helper.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 1:46 am 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Hi Sean,

Need your help again. I'm working with a program that expects parameters to be passed by reference so that they can be changed in the method call. This allows the program's methods to return multiple values. The problem is that I can put parameters in but cannot figure out how to get them back out.

This is the function code as shown by TypeLib Browser.
Code:
' ****************************************************************************************
' GenerateHTML method
' Interface name = IDataServer
' VTable offset = 40 [&H28]
' DispID = 203 [&H000000CB]
' ****************************************************************************************
FUNCTION BookCATIDataServer_GenerateHTML ALIAS "BookCATIDataServer_GenerateHTML" ( _
    BYVAL pthis AS DWORD PTR _                   ' %VT_DISPATCH <dispinterface>
  , BYVAL XSLTemplate AS STRING _                ' %VT_BSTR <DYNAMIC UNICODE STRING> [in]
  , BYVAL Filter AS STRING _                     ' %VT_BSTR <DYNAMIC UNICODE STRING> [in]
  , BYVAL StripLinks AS INTEGER _                ' %VT_BOOL <INTEGER> [in]
  , BYREF prmFilename AS STRING _                ' *%VT_BSTR <DYNAMIC UNICODE STRING> [in]
  , BYREF RecordsetGUID 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
    XSLTemplate = UCODE$(XSLTemplate)
    Filter = UCODE$(Filter)
    IF pthis = 0 THEN FUNCTION = %E_POINTER : EXIT FUNCTION
    CALL DWORD @@pthis[10] USING BookCATIDataServer_GenerateHTML(pthis, XSLTemplate, Filter, StripLinks, prmFilename, RecordsetGUID, Result) TO HRESULT
    FUNCTION = HRESULT
    prmFilename = ACODE$(prmFilename)
    RecordsetGUID = ACODE$(RecordsetGUID)

END FUNCTION

And this is the AHK code I'm trying to get to function. The server application correctly sees prmFilename or RecordsetGUID when they are valid strings. If either prmFilename or RecordsetGUID are empty strings the server should write back a value. I know the server is working properly because accessing it with a Perl based application works perfectly. In short, this AHK code works except for reading back the values written by the server application. Thanks for any help you can give me to figure out how to do this with AHK and CoHelper.

Code:
#NoEnv
#Include CoHelper.ahk

CoInitialize()

; CreateObject( "BookCAT_DataServer" )
GUID4String(CLSID_DataServer, "{19BA681F-C11A-4885-9C70-775DC7D8A6F7}")
GUID4String( IID_IDataServer, "{49FA5CA3-2B7E-49FF-AD87-EFE7953636DD}")

pthis := CreateObject(CLSID_DataServer, IID_IDataServer)

sXSLTemplate   := "BookList.xsl"
sFilter        := "Author=John Grisham"
bStriplinks    := 0
srmFilename    :=     
sRecordsetGuid :=

pXSLTemplate := SysAllocString(sXSLTemplate)
pFilter      := SysAllocString(sFilter)

prmFilename := SysAllocString(srmFilename)
VarSetCapacity(bstr1, 8 * 2, 0)
EncodeInteger(&bstr1 + 0, prmFilename)

pRecordsetGuid := SysAllocString(sRecordsetGuid)
VarSetCapacity(bstr2, 8 * 2, 0)
EncodeInteger(&bstr2 + 0, pRecordsetGuid)

If DllCall(VTable(pthis, 10)       ; GenerateHTML
  , "Uint", pthis                  ; In: connection
  , "UInt", pXSLTemplate           ; In: template
  , "UInt", pFilter                ; In: filter
  , "Int",  bStripLinks            ; In: bool Striplinks
  , "UInt", &bstr1                 ; In/Out Filename
  , "Uint", &bstr2                 ; In/Out Guid
  , "Int64P", pResult)             ; Out: Result
   MsgBox % "Connecting the database FAILED!", Exit

pbstr1 := DecodeInteger(&bstr1 + 0)
Unicode2Ansi(pbstr1, srmFilename)
SysFreeString(pbstr1)

pbstr2 := DecodeInteger(&bstr2 + 0)
Unicode2Ansi(pbstr2, sRecordsetGuid)
SysFreeString(pbstr2)

SysFreeString(pXSLTemplate)
SysFreeString(pFilter)
SysFreeString(prmFilename)
SysFreeString(pRecordsetGuid)

msgbox, % "GenerateHtml`n srmFilename: " . srmFilename . "`n sRecordsetGuid: " . sRecordsetGuid
Release(prs)
CoUnInitialize()
Exitapp 


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 2:23 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tfcahm wrote:
And this is the AHK code I'm trying to get to function.

Try this, not tested though as I don't have it in my machine.

Code:
#Include CoHelper.ahk

CoInitialize()

GUID4String(CLSID_DataServer, "{19BA681F-C11A-4885-9C70-775DC7D8A6F7}")
GUID4String( IID_IDataServer, "{49FA5CA3-2B7E-49FF-AD87-EFE7953636DD}")
pds := CreateObject(CLSID_DataServer, IID_IDataServer)

sXSLTemplate := "BookList.xsl"
sFilter      := "Author=John Grisham"
sFilename    := ""
sRecordset   := ""
bStripLinks  := False

pXSLTemplate := SysAllocString(sXSLTemplate)
pFilter      := SysAllocString(sFilter)
pFilename    := SysAllocString(sFilename)
pRecordset   := SysAllocString(sRecordset)

MsgBox, % DllCall(VTable(pds, 10), "Uint", pds, "Uint", pXSLTemplate, "Uint", pFilter, "short", -bStripLinks, "UintP", pFilename, "UintP", pRecordset, "intP", nResult, "Uint") . "|" . ErrorLevel . "|" . A_LastError . "|" . nResult

Unicode2Ansi(pFilename, sFilename)
Unicode2Ansi(pRecordset, sRecordset)

SysFreeString(pXSLTemplate)
SysFreeString(pFilter)
SysFreeString(pFilename)
SysFreeString(pRecordset)

Release(pds)
CoUninitialize()

MsgBox, % "GenerateHtml`n Filename: " . sFilename . "`n Recordset: " . sRecordset


Last edited by Sean on May 26th, 2007, 4:19 am, edited 8 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 2:49 am 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Thanks for the fast response. Unfortunately, no joy. The GenerateHTML call fails with the connection error. I'll try to figure out which parameter is causing the problem.

I don't know if you want to go that far, but you can get an functional eval copy of the program here. With a default install, the code I posted will generate an HTML file in the system temp directory.

I'll post back when after finding which parameter causes the error.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 2:59 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tfcahm wrote:
The GenerateHTML call fails with the connection error. I'll try to figure out which parameter is causing the problem.

Sorry, it was my fault.
I noticed I added "!" in If by accident, so I removed "!" immediately, but looks like you copied it before.
Please recopy it and try again.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 6:42 am 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Removing the "!" did make the call work, and the HTML file was saved to the system temp directory. However, the result returned for both variables is "0".


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 8:51 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tfcahm wrote:
However, the result returned for both variables is "0".

I'm not a psychic, at least you have to tell me what was ErrorLevel and A_LastError.

Anyway, there was one thing I thought was strange.
I neglected it as a glitch, but seems not, judging from the result and what you had said in your previous post.

I updated the script I posted. Hope to work now.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 3:21 pm 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Thanks for hanging in there with me on this. The msgboxes output from this script now are:

0|0|1008|1

475292 vs 475292 | 475476 vs 475476

GenerateHtml
Filename:
RecordsetGuid:

Sorry, I don't know where to lookup the A_LastError code. For what it is worth, this is the Perl code to do the same thing. The LastError here is 0, and the two variables are modified.
Code:
use Win32::OLE;
use Win32::OLE::Variant;
$pds = Win32::OLE->new('BookCAT.DataServer', 'Quit');

$sFilter="Author=John Grisham";
$sXSLTemplate= "BookList.xsl";
$sFilename = Variant(VT_BSTR|VT_BYREF, "");
$sRecordsetGuid = Variant(VT_BSTR|VT_BYREF, "");

$pds->GenerateHTML($sXSLTemplate, $sFilter, "FALSE", $sFilename, $sRecordsetGuid);
print Win32::OLE->LastError() . " | $sFilename | $sRecordsetGuid";

Thanks again for your help.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 4:55 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
tfcahm wrote:
For what it is worth, this is the Perl code to do the same thing.

This code doesn't accord with the one with tlb, IMO.
Although I don't know about Perl, looks like the Perl code is correct judging from the LastError, and moreover, that you said this code is working.

I updated the script again accordingly, but there still remains one unclear point to me.
Anyway, I chose the safest way except the one unclear to me.
Please inform me about the result.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 5:26 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Sean, you should fix CoHelpher so all functions return value

For instance CoInitialise can fail...

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 5:36 pm 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Here are the results:

-1073741819|0|0|0

GenerateHtml
Filename: 0
RecordsetGuid: 0

Yes, the Perl code has been used for several months and does work. I don't use Delphi here, but I'm told it works in Delphi too. If it would help I can post the Delphi code.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 5:46 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
majkinetor wrote:
For instance CoInitialise can fail...

The error code of CoInitialize is meaningless, at least from the pracitical point of view. Nothing prevents using COM after this call.
They only mean: it's already initialized or initialized as multi-thread Apartment.

Some COM/OLE feature requires specifically single-thread apartment, however, CoHelper.ahk doesn't provide a way to initialize as MTA as AHK is single-threaded anyway.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 5:53 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Its not good calling the OS function and getting "" as result anyway. U usualy look at MSDN for explanations so U may get confused when U get potato.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 25th, 2007, 5:56 pm 
Offline

Joined: May 20th, 2007, 7:48 pm
Posts: 48
Sorry, I posted too quickly and should have pointed out the last code does not resullt in an HTML file being created (nResult=0).


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 156 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7 ... 11  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: bbwht, DataLife, tkmmkt and 16 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