Nim has a lot of Windows support built in (see http://nim-lang.org/lib.html#windows-specific ), but high level COM doesn't appear to be part of that.
Since you mentioned being familiar with Python, you might try using NimBorg, which lets you embed Python in Nim. https://github.com/micklat/NimBorg
I haven't used it with the Python COM support before, but have used it with other Python modules that aren't pure Python and had good results, so it might be worth taking a look at.
If someone wants to get serious about interfacing Nim with COM objects (and perhaps using Nim to create COM interfaces) they could start with this series of tutorials on how to do COM with plain C: http://www.codeproject.com/KB/COM/com_in_c1.aspx http://www.codeproject.com/KB/COM/com_in_c2.aspx http://www.codeproject.com/KB/COM/com_in_c3.aspx http://www.codeproject.com/KB/COM/com_in_c4.aspx http://www.codeproject.com/KB/COM/com_in_c5.aspx http://www.codeproject.com/KB/COM/com_in_c6.aspx http://www.codeproject.com/KB/COM/com_in_c7.aspx http://www.codeproject.com/KB/COM/com_in_c8.aspx
Also this library could be used as a spark for a Nim library (or the core of): http://disphelper.sourceforge.net/
I managed to use Direct3D 11 in Nim. I simply ran microsoft's C compiler in preprocessor only mode with C_INTERFACE defined. Then I recreated some consts that were #define macros in the original source. I then ran the resulting files through c2nim with fairly good results.
It is definately some work, and d3d does not use very many COM features. I could see a scripting language type interface to COM being constructed fairly easily (string based dispatch), but getting everything to work as well as it does in c++ will probably be hard. Worth doing though.
I'd definitely be interested in COM support.
After getting fed up with windows updates having no information about them and having to gasp manually look up the KB ID for them to make sure Windows 10 wasn't going to invade my machine (again), I decided it'd be great to have a program to look them up and display a description of pending updates... Simple, I thought!
This led me down the COM rabbit hole (in fact, I was working from those same codeproject articles you posted willyh), and I did start to make some headway, but it's a fairly big job I think.
I wish there was something we could just run c2nim against; btw that's an interesting idea, using the C preprocessor for that Demos.
It'd be amazing to have a high level COM interface in Nim because it opens up all sorts of cool automation stuff, and ultimately may spur ease of scripting in business applications.
Also, Nimbecile: I'm interested in automating Excel too - did you have any luck? I don't think NimBorg is the way I'd want to go with this. Perhaps I'll carry on and hack out a COM lib, but this will probably take a while and ultimately I'm not sure what it would look like in Nim (aka using Nim's fancy features to make scripting easier).
To be honest, I don't know when the wrapper will be ready. I recently lost a large portion of my current work due to an incident with my laptop, and in addition, college classes have started again (I'm a student). In addition, my main focus is producing a bare-bones wrapper, writing additions that make using such a wrapper is lower-priority.
If you need to wrap a specific COM interface, it's not too hard. For instance, given the IUnknown interface definition found in basetyps.h:
typedef struct IUnknownVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IUnknown * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IUnknown * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IUnknown * This);
END_INTERFACE
} IUnknownVtbl;
interface IUnknown
{
CONST_VTBL struct IUnknownVtbl *lpVtbl;
};
and this 'windefs.c2nim' file:
#def STDMETHODCALLTYPE
#def BEGIN_INTERFACE
#def END_INTERFACE
#def _COM_Outptr_
#def CONST_VTBL
#def interface struct
We can invoke c2nim with:
--stdcall --skipcomments windefs.c2nim iunknown.h
To get:
type
IUnknownVtbl* = object
QueryInterface*: proc (This: ptr IUnknown; riid: REFIID; ppvObject: ptr pointer): HRESULT {.
stdcall.}
AddRef*: proc (This: ptr IUnknown): ULONG {.stdcall.}
Release*: proc (This: ptr IUnknown): ULONG {.stdcall.}
IUnknown* = object
lpVtbl*: ptr IUnknownVtbl
Note that it's important that the procedure definitions are annotated with the {.stdcall.} as that's the calling convention used by COM objects from C programs.
I'm currently trying to get rid of all that obj.lpVtbl.Method(obj,....) stuff but nim has pretty poor support for forwarding in this way so I'm a bit stuck. It's also quite hard to pass an expression like Method(a,b) into a template since nim likes to try and call that as a procedure.
Also, the directnimrod package now includes a wrapper for unknwn.h, but keep in mind you don't actually need that unless you have methods that actually take a param of type ptr IUnknown
It's also quite hard to pass an expression like Method(a,b) into a template since nim likes to try and call that as a procedure.
Not if you use untyped for the template's parameter type.