Click here to Skip to main content
12,890,181 members (44,448 online)
Click here to Skip to main content

Stats

42.5K views
445 downloads
25 bookmarked
Posted 18 Apr 2010

Using COM Objects in Scripting Languages -- Part 2 (Python)

, 20 Apr 2010 CPOL
This article shows how to instantiate a COM object in Python and use its methods and properties.
// SimpleCOM.idl : IDL source for SimpleCOM
//

// This file will be processed by the MIDL tool to
// produce the type library (SimpleCOM.tlb) and marshalling code.

import "oaidl.idl";
import "ocidl.idl";

[
	object,
	uuid(3B83ACE6-D890-4cff-8CDF-AC6C41A78E78),
	dual,
	nonextensible,
	helpstring("IColor Interface"),
	pointer_default(unique)
]
interface IColor : IDispatch{
	[id(1), helpstring("method SetColor")] HRESULT SetColor([in] OLE_COLOR iColor);
	[id(2), helpstring("method GetColor")] HRESULT GetColor([out] OLE_COLOR* oColor);
};
[
	object,
	uuid(60706484-8A6F-409b-8DCE-7C14DCABC8E3),
	dual,
	nonextensible,
	helpstring("IPoint Interface"),
	pointer_default(unique)
]
interface IPoint : IDispatch{
	[propget, id(1), helpstring("property X")] HRESULT X([out, retval] DOUBLE* pVal);
	[propput, id(1), helpstring("property X")] HRESULT X([in] DOUBLE newVal);
	[propget, id(2), helpstring("property Y")] HRESULT Y([out, retval] DOUBLE* pVal);
	[propput, id(2), helpstring("property Y")] HRESULT Y([in] DOUBLE newVal);
	[propget, id(3), helpstring("property Z")] HRESULT Z([out, retval] DOUBLE* pVal);
	[propput, id(3), helpstring("property Z")] HRESULT Z([in] DOUBLE newVal);
	[id(4), helpstring("method Distance")] HRESULT Distance([in] IPoint* iPoint, [out,retval] DOUBLE* oDist);
	[id(5), helpstring("method SetCoord")] HRESULT SetCoord([in] DOUBLE iX, [in] DOUBLE iY, [in] DOUBLE iZ);
	[id(6), helpstring("method GetCoord")] HRESULT GetCoord([out] DOUBLE* oX, [out] DOUBLE* oY, [out] DOUBLE* oZ);
};
[
	object,
	uuid(2FF6CB42-0C57-455D-9A7E-2CE1E74F775B),
	dual,
	nonextensible,
	helpstring("IGraphicPoint Interface"),
	pointer_default(unique)
]
interface IGraphicPoint : IDispatch{
	[id(1), helpstring("method Draw")] HRESULT Draw(void);
};
[
	uuid(FA3BF2A2-7220-47ED-8F07-D154B65AA031),
	version(1.0),
	helpstring("SimpleCOM 1.0 Type Library")
]
library SimpleCOMLib
{
	importlib("stdole2.tlb");
	[
		uuid(33E1D707-B576-4D3F-B76D-644D2A20E942),
		helpstring("GraphicPoint Class")
	]
	coclass GraphicPoint
	{
		[default] interface IGraphicPoint;
		interface IPoint;
		interface IColor;
		interface IDispatch;
	};
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sharjith
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170424.1 | Last Updated 20 Apr 2010
Article Copyright 2010 by Sharjith
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid