AutoHotkey Community

It is currently May 25th, 2012, 7:16 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 646 posts ]  Go to page 1, 2, 3, 4, 5 ... 44  Next
Author Message
 Post subject: COM Standard Library
PostPosted: September 8th, 2007, 2:10 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
This is a standard library COM.ahk.
It requires at least AHK build 1.0.47.00.
Before downloading, please read first about Standard Library.

DOWNLOAD: COM.zip or COM_L.zip (for AutoHotkey_L) or AutoHotkey32/64 (COM is built into).

PREREQUISITE: ComCall via DllCall (Allowing Function Pointer in DllCall)

The usage of COM_Invoke():

If it has the form in VBS-like scripts as
Code:
value = Object.Function(param1, param2, ...) ; Method, PropertyGet
it'll be translated like
Code:
value := COM_Invoke(Object, "Function", param1, param2, ...)


And, if
Code:
Object.Function(param1, param2, ...) = value ; PropertyPut, PropertyPutRef
then similarly with the above
Code:
COM_Invoke(Object, "Function", param1, param2, ..., value)
However, there exist occasions the above simple form becomes ambiguous. In those cases, can force it to use PropertyPut by appending to the function name the artificial suffix "=" like:
Code:
COM_Invoke(Object, "Function=", param1, param2, ..., value)


There are some occasions where another COM Object ObjPrm should be a parameter. In that case, prefix it with "+" like:
Code:
COM_Invoke(Object, "Function", ..., "+" . ObjPrm , ...) ; never directly prefix it like +ObjPrm.
As a consequence, "+0" will play the role of VBS Nothing.

And, "-0" will represent VBS missing parameter. For eample
Code:
Object.Function(..., param1, , param3, ...)
in VBS-like scripts can be written as
Code:
COM_Invoke(Object, "Function", ..., param1, "-0" , param3, ...)


Finally, to control the error message pop-up of COM Library, call
Code:
COM_Error(b) ; b := 0/1 for off/on


REF. If like to use dot syntax, can use ez_invoke() and/or COM_InvokeDeep().

PS. The last updated time is the last edited time of this post.


Last edited by Sean on March 2nd, 2011, 5:02 am, edited 23 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 10:57 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thx, it was about time to sort COM funcs out.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 12:53 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
majkinetor wrote:
Thx, it was about time to sort COM funcs out.

Thanks. Here are the function lists. I'll include it in the COM.zip in the next update. Those in italic are optional parameters.

Quote:
COM_Invoke(pdisp, sName, arg1, ...) ; Optional arg up to 9.
COM_Invoke_(pdisp, sName, type1, arg1, ...) ; Optional type & arg up to 9.
COM_CoInitialize()
COM_CoUninitialize()
COM_ActiveXObject(ProgID)
COM_CreateObject(CLSID, IID)
COM_ConnectObject(psource, prefix, DIID)
COM_GetObject(Moniker)
COM_GetActiveObject(ProgID)
COM_Release(ppv)
COM_AddRef(ppv)
COM_QueryInterface(ppv, IID)
COM_QueryService(ppv, SID, IID)
COM_VTable(ppv, idx)
COM_AtlAxWinInit(Version)
COM_AtlAxWinTerm(Version)
COM_AtlAxGetControl(hWnd, Version)
COM_AtlAxAttachControl(pdsp, hWnd, Version)
COM_AtlAxCreateControl(hWnd, Name, Version)
COM_AtlAxCreateContainer(hWnd, l, t, w, h, Name, Version)
COM_AtlAxGetContainer(pdsp)
COM_DispGetParam(pDispParams, Position, vtType)
COM_Ansi4Unicode(pString, nSize)
COM_Unicode4Ansi(ByRef wString, sString, nSize)
COM_Ansi2Unicode(ByRef sString, ByRef wString, nSize)
COM_Unicode2Ansi(ByRef wString, ByRef sString, nSize)
COM_CLSID4ProgID(ByRef CLSID, sProgID, nOffset = 0)
COM_GUID4String(ByRef CLSID, sString, nOffset = 0)
COM_ProgID4CLSID(pCLSID)
COM_String4GUID(pGUID)
COM_SysAllocString(sString)
COM_SysFreeString(bstr)
COM_SysStringLen(bstr)
COM_SafeArrayDestroy(psa)
COM_VariantClear(pvarg)
COM_CoTaskMemAlloc(cb)
COM_CoTaskMemFree(pv)
COM_CoCreateGuid()
COM_OleInitialize()
COM_OleUninitialize()
COM_IsEqualGUID(pGUID1, pGUID2)
COM_FindConnectionPoint(pdp, DIID)
COM_GetConnectionInterface(pcp)
COM_Advise(pcp, psink)
COM_Unadvise(pcp, nCookie)
COM_DispInterface()
COM_CreateIDispatch()
COM_GetDefaultInterface()
COM_GetDefaultEvents()
COM_GetGuidOfName()
COM_GetTypeInfoOfGuid()


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 1:20 pm 
Offline

Joined: March 16th, 2005, 10:33 pm
Posts: 968
Location: Frisia
Excellent!

Though I understand not even half of it, this is invaluable for advanced options in AHK.

:)

_________________
Image mirror 1mirror 2mirror 3ahk4.me • PM or Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 1:29 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5346
Location: UK
Small error...

Code:
COM.ahk (120) : ==> Call to nonexistent function.
     Specifically: Release(NumGet(this+16)) . Release(NumGet(this+8)) . COM_CoTaskMemFree(this)


btw. what's the difference between Unicode4Ansi and Unicode2Ansi?

_________________
GitHubScriptsIronAHK Contact by email not private message.


Last edited by polyethene on October 28th, 2009, 11:49 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 3:28 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Titan wrote:
Small error...

Oops, sorry. I updated it.

Quote:
btw. what's the difference between Unicode4Ansi and Unicode2Ansi?

Here, 2 means To and 4 means From or For. So,

Quote:
Unicode4Ansi(ByRef wString, sString) obtains (ByRef) Unicode wString From provided (ByVal) ANSI sString.
Unicode2Ansi(ByRef wString, ByRef sString) converts provided (ByRef) Unicode wString To (ByRef) ANSI sString.
Ansi2Unicode(ByRef sString, ByRef wString) converts provided (ByRef) ANSI sString To (ByRef) Unicode wString.
Ansi4Unicode(pString) converts the Unicode string at address pString to ANSI string and returns it.

I introduced these 4 functions, in addition to the already existed 2 functions, to reduce the usage of ByRef parameters.
My original plan was to ditch 2 in favor of 4, but these 2 also have their own merit, I finally decided to leave them too.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 8th, 2007, 11:45 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2541
Sean wrote:
I uploaded standard library COM.ahk.
Thanks :)
Sean wrote:
Those in italic are optional parameters.
Italic is really hard to distinguish here.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 12:55 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
corrupt wrote:
Sean wrote:
Those in italic are optional parameters.
Italic is really hard to distinguish here.

Yeh, I first planned to use them in the code box, but italic didn't work in code box, so quoted them instead. I included the text file in this format in COM.zip.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 3:01 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I was playing a little more with the standard library thing, more precisely with Lib subdirectory. If want to use still CoHelper.ahk, rather than altering the existing scripts to adapt to COM.ahk, you may put CoHelper.ahk to Lib subdirectory after adding a dummy function to it:

Code:
CoHelper_Init()
{
}

Then, remove #Include CoHelper.ahk, and call instead CoHelper_Init() at the start of the script.
BTW, what I'm actually using is:

Code:
CoHelper_Init()
{
   CoInitialize()
}

CoHelper_Term()
{
   CoUninitialize()
}

and call them instead of CoInitialize() and CoUninitialize().

OK, it may not be really different with #Include, but the pro of it is that the included file can reside in the constant place, the Lib subdirectory. The con is that the dummy function can't be placed in an arbitrary position in the script, it should be called before any other functions in the included file.

Just a tip for the users who aren't aware of it yet.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 4:06 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
not sure if this is helpful, likely obvious, but just in case.. simple formatting suggestion example for helpfile text/post help text type thing..
Code:
COM_Invoke(pdisp, sName, [arg1], ...) ; Optional arg up to 9.
COM_Invoke_(pdisp, sName, [type1], [arg1], ...) ; Optional type & arg up to 9.
COM_DispGetParam(pDispParams, [Position], [vtType])
COM_AtlAxWinInit([Version])
COM_AtlAxWinTerm([Version])
COM_AtlAxGetControl(hWnd, [Version])
COM_AtlAxAttachControl(pdsp, hWnd, [Version])
COM_AtlAxCreateControl(hWnd, Name, [Version])
COM_AtlAxCreateContainer(hWnd, l, t, w, h, [Name], [Version])
COM_AtlAxGetContainer(pdsp)
COM_CoInitialize()
COM_CoUninitialize()
COM_ActiveXObject(ProgID)
COM_CreateObject(CLSID, [IID])
COM_ConnectObject(psource, [prefix], [DIID])
COM_GetObject(Moniker)
COM_GetActiveObject(ProgID)
COM_Release(ppv)
COM_AddRef(ppv)
COM_QueryInterface(ppv, IID)
COM_QueryService(ppv, SID, IID)
COM_VTable(ppv, idx)
COM_Ansi2Unicode(ByRef sString, ByRef wString, [nSize])
COM_Unicode2Ansi(ByRef wString, ByRef sString, [nSize])
COM_Unicode4Ansi(ByRef wString, sString, [nSize])
COM_Ansi4Unicode(pString, [nSize])

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 4:54 pm 
Offline
User avatar

Joined: December 29th, 2004, 1:28 pm
Posts: 2541
Sean wrote:
If want to use still CoHelper.ahk, rather than altering the existing scripts to adapt to COM.ahk, you may put CoHelper.ahk to Lib subdirectory after adding a dummy function to it:
Another alternative could be to rename CoHelper.ahk to CoInitialize.ahk and remove the #Include line.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 9th, 2007, 6:08 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
corrupt wrote:
Another alternative could be to rename CoHelper.ahk to CoInitialize.ahk and remove the #Include line.


or, on same line of thought, but avoids confusion over the CoHelper.ahk file name

simply add a CoInitialize.ahk to the lib that contains #Include CoHelper.ahk

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2007, 10:13 am 
Hi. I wasn't successfull with identifying mandatory details to extract from the code below, to be used with one of those/your functions. :(
Target is to get the Artist (Track/Duration/Album) name of the currently playing track in Windows Media Player (WMP).
Hope you can help me & thx for listening. :)
Code:
#define _ATL_APARTMENT_THREADED

#include <atlbase.h>
#include <atlcom.h>
#include <atlwin.h>
#include <initguid.h>
#include "RemoteHost.h"

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
END_OBJECT_MAP()

int PrintCurrSong()
{
HRESULT hr = S_OK;
RECT rcClient;
CComPtr<IObjectWithSite> spHostObject;
CComPtr<IAxWinHostWindow> spHost;
CComObject<CRemoteHost> *pRemoteHost = NULL;
CComPtr<IWMPPlayer4> m_spPlayer;


// Create an ActiveX control container
AtlAxWinInit();
CAxWindow *m_pView = new CAxWindow();
if(!m_pView)
{
hr = E_OUTOFMEMORY;
}

if(SUCCEEDED(hr))
{
m_pView->Create(NULL, rcClient, NULL, WS_VISIBLE , WS_EX_CLIENTEDGE);

if(::IsWindow(m_pView->m_hWnd))
{
hr = m_pView->QueryHost(IID_IObjectWithSite, (void **)&spHostObject);
if(!spHostObject.p)
{
hr = E_POINTER;
}
}
}

// Create remote host which implements IServiceProvider and IWMPRemoteMediaServices
if(SUCCEEDED(hr))
{
hr = CComObject<CRemoteHost>::CreateInstance(&pRemoteHost);
if(pRemoteHost)
{
pRemoteHost->AddRef();
}
else
{
hr = E_POINTER;
}
}

// Set site to the remote host
if(SUCCEEDED(hr))
{
hr = spHostObject->SetSite((IWMPRemoteMediaServices *)pRemoteHost);
}

if(SUCCEEDED(hr))
{
hr = m_pView->QueryHost(&spHost);
if(!spHost.p)
{
hr = E_NOINTERFACE;
}
}

// Create WMP Control here

if(SUCCEEDED(hr))
{
hr = spHost->CreateControl(CComBSTR(L"{6BF52A52-394A-11d3-B153-00C04F79FAA6}"), m_pView->m_hWnd, NULL);
}

if(SUCCEEDED(hr))
{
hr = m_pView->QueryControl(&m_spPlayer);
if(!m_spPlayer.p)
{
hr = E_NOINTERFACE;
}
IWMPMedia *media;
m_spPlayer->get_currentMedia(&media);
CComBSTR str;
media->get_name(&str);
CW2A printstr(str);
printf("%s\n", printstr);
}

// Release remote host object
if(pRemoteHost)
{
pRemoteHost->Release();
}
return 1; // Let the system set the focus
}

int _tmain()
{
HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);

HRESULT hRes = CoInitialize(NULL);

_ASSERTE(SUCCEEDED(hRes));
_Module.Init(ObjectMap, hInstance, &LIBID_ATLLib);

hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER,
REGCLS_MULTIPLEUSE);

_ASSERTE(SUCCEEDED(hRes));

PrintCurrSong();
_Module.RevokeClassObjects();
_Module.Term();
CoUninitialize();
return 0;
}


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2007, 10:38 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
he he :D

Maybe you shoud practice a bit more, I will send you adequate tunes for inspiration :P

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 13th, 2007, 11:19 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
BoBo¨ wrote:
Target is to get the Artist (Track/Duration/Album) name of the currently playing track in Windows Media Player (WMP).

Exactly from where are you trying to get the infos?
The code you attached has nothing to do with wmplayer.exe, it's about how to create container object using ATL library and then to host the WMPlayer.OCX control.
I'm not aware of any COM way to retrieve the infos from the running wmplayer.exe.


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 1, 2, 3, 4, 5 ... 44  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [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