469,312 Members | 2,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Active X DLL tips?


I want to use and Active X DLL in Python applications. I have the
win32all stuff installed and the "Excel.Application" example in the
Client QuickStart section of the manual works OK, so I guess it is
installed correctly.

Problem comes when I want to use the objects in the OPCDA library. In VB
I would include the library in the references and could then do
something like:

Dim foo as OPCServer
dim baa as OPCGroups
(lots of lower level objects omitted)

set foo=New OPCServer
foo.Connect <Server details>
set baa=foo <Call for getting a new OPCGroups object>
(code continues in a similar manner)

Leading on from the Excel example, I have tried using client.Dispatch
with "OPCServer", "OPCAutomation.OPCServer" and a few other
combinations, but I cannot get a valid object. Either I am told the
string is invalid, or I get no error but the variable which the object
was supposed to be assigned to is.....not assigned.

Maybe (as warned in the docs) the COM browser is not correctly reporting
the names I should use. It mentions the VC COM browser, but if you don't
have that are there other valid alternatives?

I have looked at the gencache functions for generating a Python module
from the type library, but I am not sure about the parameters, in
particular, what should the lcid be? Also, what is the correct way to
pass an IID, as a string complete with the hyphens?

I have looked around for examples but all I have found so far is either
accessing applications such as Excel, IE and outlook, or building
clients to test servers that have been created with Python.

I suspect that maybe I sould be doing things a bit differently to access
a vanilla Automation DLL.

Tips anyone?
Jul 18 '05 #1
1 2446
Got there in the end. For the benefit of other clueless souls who turn
up my post in searches, this is what I used:

import win32com.client
OPCDA=win32com.client.gencache.GetModuleForTypelib ('{28E68F91-8D75-11D1-8DC3-3C302A000000}',0,1,0) AnOPCServer=OPCDA.OPCServer.default_interface

This generates what I think is a 'Class Factory' in OPCDA, and this can
be used to generate an OPCServer object, as well as other OPC objects,
allthougth of course these are usually generated by calls to higher
level objects.

It would be nice to have a few tips and examples on this type of usage
in the Client QuickStart guide. Unfortunately I have little idea of what
I am doing so I am not the person to write it.

The GetModuleForTypeLib is documented in the win32com helpfile, the
parameters are:

IID,lcid,major,minor

IID - Get this using the COM browser. Look for OPC Automation 2.0, the
'filename' entry in the Type Library should point to opcdaauto.dll

lcid - this is a 'locale' ID. One of my mistakes was tring to set this
to a typical value for my (Italian) PC. Set to 0 and use the standard
conventions.

major & minor - Get the major and minor versions by looking at the
property of the DLL. In this case the type library is called OPC
Automation 2.0 but the DLL is version 1.0 . This may sound odd but the
2.0 refers to the OPC standard that is implemented, not the version
number of the DLL which implements it!
Roger wrote:
I want to use and Active X DLL in Python applications. I have the
win32all stuff installed and the "Excel.Application" example in the
Client QuickStart section of the manual works OK, so I guess it is
installed correctly.

Problem comes when I want to use the objects in the OPCDA library. In VB
I would include the library in the references and could then do
something like:

Dim foo as OPCServer
dim baa as OPCGroups
(lots of lower level objects omitted)

set foo=New OPCServer
foo.Connect <Server details>
set baa=foo <Call for getting a new OPCGroups object>
(code continues in a similar manner)

Leading on from the Excel example, I have tried using client.Dispatch
with "OPCServer", "OPCAutomation.OPCServer" and a few other
combinations, but I cannot get a valid object. Either I am told the
string is invalid, or I get no error but the variable which the object
was supposed to be assigned to is.....not assigned.

Maybe (as warned in the docs) the COM browser is not correctly reporting
the names I should use. It mentions the VC COM browser, but if you don't
have that are there other valid alternatives?

I have looked at the gencache functions for generating a Python module
from the type library, but I am not sure about the parameters, in
particular, what should the lcid be? Also, what is the correct way to
pass an IID, as a string complete with the hyphens?

I have looked around for examples but all I have found so far is either
accessing applications such as Excel, IE and outlook, or building
clients to test servers that have been created with Python.

I suspect that maybe I sould be doing things a bit differently to access
a vanilla Automation DLL.

Tips anyone?

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Johan | last post: by
1 post views Thread by Stinky Pete | last post: by
2 posts views Thread by AndersBj | last post: by
3 posts views Thread by prakashwadhwani | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.