AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

COM Standard Library
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Sep 08, 2007 2:10 am    Post subject: COM Standard Library Reply with quote

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.

The usage of COM_Invoke():

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

And, if
Code:
Object.Function = param ; PropertyPut, PropertyPutRef
then similarly with the above
Code:
COM_Invoke(Object, "Function", param)
; OR
COM_Invoke(Object, "Function=", param) ; notice the suffix = in the function name

There are some occasions where another COM Object ObjPrm should be a parameter. In that case, please prefix it with "+" like
Code:
COM_Invoke(Object, "Function", "+" . ObjPrm) ; never directly prefix it like +ObjPrm.

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


Last edited by Sean on Sun Jun 29, 2008 12:58 pm; edited 5 times in total
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3615
Location: Belgrade

PostPosted: Sat Sep 08, 2007 10:57 am    Post subject: Reply with quote

Thx, it was about time to sort COM funcs out.
_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Sep 08, 2007 12:53 pm    Post subject: Reply with quote

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()
Back to top
View user's profile Send private message
daonlyfreez



Joined: 16 Mar 2005
Posts: 744
Location: Berlin

PostPosted: Sat Sep 08, 2007 1:20 pm    Post subject: Reply with quote

Excellent!

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

Smile
_________________
(sorry, homesite offline atm)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Titan



Joined: 11 Aug 2004
Posts: 5026
Location: imaginationland

PostPosted: Sat Sep 08, 2007 1:29 pm    Post subject: Reply with quote

Small error...

Code:
C:\Users\Admin\Documents\Scripts\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?
_________________

RegExReplace("irc.freenode.net/autohotkey", "^(?=(.(?=[\0-r\[]*((?<=\.).))))(?:[c-\x73]{2,8}(\S))+((2)|\b[^\2-]){2}\D++$", "$u3$1$3$4$2")
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sat Sep 08, 2007 3:28 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2391

PostPosted: Sat Sep 08, 2007 11:45 pm    Post subject: Reply with quote

Sean wrote:
I uploaded standard library COM.ahk.
Thanks Smile
Sean wrote:
Those in italic are optional parameters.
Italic is really hard to distinguish here.
Back to top
View user's profile Send private message Visit poster's website
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sun Sep 09, 2007 12:55 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Sun Sep 09, 2007 3:01 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Joy2DWorld



Joined: 04 Dec 2006
Posts: 418
Location: Galil, Israel

PostPosted: Sun Sep 09, 2007 4:06 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
corrupt



Joined: 29 Dec 2004
Posts: 2391

PostPosted: Sun Sep 09, 2007 4:54 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Visit poster's website
Joy2DWorld



Joined: 04 Dec 2006
Posts: 418
Location: Galil, Israel

PostPosted: Sun Sep 09, 2007 6:08 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Thu Sep 13, 2007 10:13 am    Post subject: Reply with quote

Hi. I wasn't successfull with identifying mandatory details to extract from the code below, to be used with one of those/your functions. Sad
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. Smile
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;
}
Back to top
majkinetor



Joined: 24 May 2006
Posts: 3615
Location: Belgrade

PostPosted: Thu Sep 13, 2007 10:38 am    Post subject: Reply with quote

he he Very Happy

Maybe you shoud practice a bit more, I will send you adequate tunes for inspiration Razz
_________________
Back to top
View user's profile Send private message MSN Messenger
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Thu Sep 13, 2007 11:19 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10  Next
Page 1 of 10

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group