Click here to Skip to main content
12,360,217 members (56,939 online)
Click here to Skip to main content

Stats

36.3K views
406 downloads
25 bookmarked
Posted

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.
// TestCOM.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "TestCOM.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		_tprintf(_T("Fatal Error: MFC initialization failed\n"));
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		CoInitialize(NULL);
		IGraphicPoint* pGrPt = NULL;
		IPoint* pPnt = NULL;
		HRESULT hr = CoCreateInstance(CLSID_GraphicPoint, NULL, CLSCTX_INPROC, IID_IPoint, (void**)&pPnt);
		if(SUCCEEDED(hr))
		{
			pPnt->put_X(10);
			hr = pPnt->QueryInterface(IID_IGraphicPoint, (void**)&pGrPt);
			pPnt->Release();
			if(SUCCEEDED(hr))
			{
				pGrPt->Draw();
				pGrPt->Release();
			}
		}
		CoUninitialize();
	}

	return nRetCode;
}

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
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

You may also be interested in...

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