Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COM and Python

Status
Not open for further replies.

Scorpius

Programmer
Joined
Aug 28, 2005
Messages
1
Location
US
I have this piece of C++ code which creates a COM object and am looking to redo this in Python using win32com.client, but just cant seems to find a how to or example below is the C++ code.

C++ CODE:
//Initialize COM
CheckHR( CoInitialize(NULL) );
//Get an Instance of INetConnectionManager
CheckHR( CoCreateInstance(CLSID_ConnectionManager, NULL, CLSCTX_SERVER, IID_INetConnectionManager, (void**)&pManager) );

PYTHON CODE: (thus far)
//Create COM object, not working
object = win32com.client.Dispatch("INetConnectionManager")

 
I suppose you would like to use a style like that:
Code:
from win32com import *
import pythoncom
from pythoncom import *
from pywintypes import *


CLSCTX_INPROC_SERVER        = 1 << 0
CLSCTX_INPROC_HANDLER       = 1 << 1
CLSCTX_LOCAL_SERVER         = 1 << 2
CLSCTX_INPROC_SERVER16      = 1 << 3
CLSCTX_REMOTE_SERVER        = 1 << 4
CLSCTX_INPROC_HANDLER16     = 1 << 5
CLSCTX_RESERVED1            = 1 << 6
CLSCTX_RESERVED2            = 1 << 7
CLSCTX_RESERVED3            = 1 << 8
CLSCTX_RESERVED4            = 1 << 9
CLSCTX_NO_CODE_DOWNLOAD     = 1 << 10
CLSCTX_RESERVED5            = 1 << 11
CLSCTX_NO_CUSTOM_MARSHAL    = 1 << 12
CLSCTX_ENABLE_CODE_DOWNLOAD = 1 << 13
CLSCTX_NO_FAILURE_LOG       = 1 << 14
CLSCTX_DISABLE_AAA          = 1 << 15
CLSCTX_ENABLE_AAA           = 1 << 16
CLSCTX_FROM_DEFAULT_CONTEXT = 1 << 17

CLSCTX_SERVER = CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER | CLSCTX_REMOTE_SERVER
CLSCTX_ALL = CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER| CLSCTX_LOCAL_SERVER| CLSCTX_REMOTE_SERVER

IID_IUnknown  = '{00000000-0000-0000-C000-000000000046}'

IID_IUnknown  = pythoncom.MakeIID('{00000000-0000-0000-C000-000000000046}')
IID_IDispatch = pythoncom.MakeIID('{00020400-0000-0000-C000-000000000046}')
CLSIS_Access   = pythoncom.MakeIID('{73A4C9C1-D68D-11D0-98BF-00A0C90DC8D9}')

pythoncom.CoInitialize()

unk = pythoncom.CoCreateInstance(CLSIS_Excel, None, CLSCTX_LOCAL_SERVER, IID_IUnknown)
disp = unk.QueryInterface(IID_IDispatch)



print "salut"
CoUninitialize()

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top